unplugin
unplugin copied to clipboard
webpack Plugin is not a constructor
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
However, since the plugins provided by unplugin are anonymous arrow functions
So it can't be instantiated
Additional context
No response
Logs
No response
the solution
const Config = require('webpack-chain');
const myPlugin = require('my-plugin/webpack');
const config = new Config();
config
.plugin('xxx')
- .use(myPlugin);
+ .use(myPlugin());
According to the docs, our design is as follows.
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-starter/webpack')({ /* options */ })
]
}