unjs / unplugin

Unified plugin system for Vite, Rollup, Webpack, esbuild, Rolldown, and more
https://unplugin.unjs.io
MIT License
3.02k stars 109 forks source link

webpack Plugin is not a constructor #385

Closed eightHundreds closed 3 months ago

eightHundreds commented 3 months ago

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 commented 3 months ago

the solution

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

According to the docs, our design is as follows.

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