unplugin icon indicating copy to clipboard operation
unplugin copied to clipboard

webpack Plugin is not a constructor

Open eightHundreds opened this issue 1 year ago • 1 comments

Environment

node v16.19.0 unplugin 1.10.1

Reproduction

const Config = require('webpack-chain');
const myPlugin = require('my-plugin/webpack');
const config = new Config();
config
  .plugin('xxx')
    .use(myPlugin);

Describe the bug

Inside the webpack-chain it will instantiate the plugin as a constructor Code 2024-06-18 11 36 57 However, since the plugins provided by unplugin are anonymous arrow functions image

So it can't be instantiated image

Additional context

No response

Logs

No response

eightHundreds avatar Jun 18 '24 03:06 eightHundreds

the solution

const Config = require('webpack-chain');
const myPlugin = require('my-plugin/webpack');
const config = new Config();
config
  .plugin('xxx')
-    .use(myPlugin);
+    .use(myPlugin());

eightHundreds avatar Jun 18 '24 03:06 eightHundreds

According to the docs, our design is as follows.

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-starter/webpack')({ /* options */ })
  ]
}

sxzz avatar Jul 01 '24 09:07 sxzz