Webpack从V4更新到V5:this.plugin不是函数



这是我的Webpack.json版本:

"webpack": "5.25.0",
"webpack-cli": "4.5.0",
"webpack-merge": "5.7.3"

所以最新版本适用于所有人。我从4.31开始使用webpack版本。

在我的webpack.production.js中,在插件数组中,我有:

new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[hash].app.css',
}),
function symfonyAssetsVersion() {
this.plugin('done', (stats) => {
fs.writeFile(
path.join(__dirname, 'config/packages/', 'assets_version.yaml'),
`parameters:n    assets_hash: ${stats.hash}n`,
(err) => { if (err) throw err; }
);
});
},
],
My CircleCi tool tells that:

[webpack-cli] TypeError: this.plugin is not a function
at Compiler.symfonyAssetsVersion (/app/webpack.production.js:27:18)
at createCompiler (/app/node_modules/webpack/lib/webpack.js:69:12)
at create (/app/node_modules/webpack/lib/webpack.js:118:16)
at webpack (/app/node_modules/webpack/lib/webpack.js:126:47)
at WebpackCLI.f [as webpack] (/app/node_modules/webpack/lib/index.js:41:15)
at WebpackCLI.createCompiler (/app/node_modules/webpack-cli/lib/webpack-cli.js:1678:29)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3) ```
Any idea on how to fix the this.plugin is not a function ? 
Thank you

您必须将symfonyAssetsVersion()重写为与Webpack 5的api匹配的自定义插件。您可以在此处阅读更多信息:https://webpack.js.org/contribute/writing-a-plugin/.

基本上,在原型上创建一个带有application的新类。然后挂接到compiler.hooks.done,回调中会提供统计信息。

相关内容

最新更新