Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

support asset modules with generator #344

Closed
xurna opened this issue Nov 29, 2022 · 2 comments
Closed

support asset modules with generator #344

xurna opened this issue Nov 29, 2022 · 2 comments

Comments

@xurna
Copy link

xurna commented Nov 29, 2022

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

When I use webapck 5 , to add a module rule width generator,
not use webapck chain,the code like this:
rules: [ { test: /\.png/, type: 'asset', generator: { filename: 'img/[name].[hash:8][ext]' } } ]
to use weback chain, the code is
config.module .rule('images') .type('asset') .generator({ filename: 'img/[name].[hash:8][ext]', }) .parser({ dataUrlCondition: { maxSize: 5 * 1024 })
but it accur error:
TypeError: config.module.rule(...).test(...).type(...).generator is not a function

I found that the lastest webpack-chain is not support generator, so
Here is the diff that solved my problem:

diff --git a/node_modules/webpack-chain/src/Rule.js b/node_modules/webpack-chain/src/Rule.js
index f300699..ef383b5 100644
--- a/node_modules/webpack-chain/src/Rule.js
+++ b/node_modules/webpack-chain/src/Rule.js
@@ -39,6 +39,7 @@ const Rule = Orderable(
         'sideEffects',
         'test',
         'type',
+        'generator',
       ]);
     }
 

This issue body was partially generated by patch-package.

@s-wada-np
Copy link

Do it like this.

{
  chainWebpack: (config) => {
    config.module
      .rule('svg')
      .test(/\.svg$/)
      .type('asset/inline')
      .set(
        'generator',
        { dataUrl: (content) => svgToMiniDataURI(content.toString()) },
      );
  },
}

@edmorley edmorley closed this as completed Feb 3, 2024
@edmorley
Copy link
Member

edmorley commented Feb 4, 2024

Closing since unfortunately this project is no longer maintained:
#358

@edmorley edmorley closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants