解决webpack5下使用html-webpack-plugin报错

3,131 阅读1分钟

升级webpack5之后,打包文件报错

(node:60416) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)

原因是html-webpack-plugin的next版本才支持webpack5

解决方法:移除之前的html-webpack-plugin,安装next版本

yarn add html-webpack-plugin@next -D