webpack4升級extract-text-webpack-plugin和UglifyJsPlugin問題


webpack4升級extract-text-webpack-plugin和UglifyJsPlugin問題

1.  使用了extract-text-webpack-plugin插件后,編譯出錯,代碼如下:

new ExtractTextPlugin('[name].css')

報錯信息如下:

Tapable.plugin is deprecated. Use new API on `.hooks` instead 報錯

webpack is watching the files…

(node:64840) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
 1 77% module and chunk tree optimization bound /Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/webpack/lib/Chunk.js:824
    throw new Error(
    ^

Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
    at Chunk.get (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/webpack/lib/Chunk.js:824:9)
    at /Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/extract-text-webpack-plugin/index.js:260:39
    at Array.forEach (native)
    at ExtractTextPlugin.<anonymous> (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/extract-text-webpack-plugin/index.js:255:11)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/tapable/lib/Hook.js:35:21)

解決方案:用的應該是webpack4吧,換成mini-css-extract-plugin就好了,用法:https://www.npmjs.com/package/mini-css-extract-plugin

2.使用new webpack.optimize.UglifyJsPlugin()時報錯

如下代碼:

new webpack.optimize.UglifyJsPlugin({
  sourceMap: true,
  compress: {
    warnings: false
  }
}),

報錯信息如下:

Error: webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead.
    at Object.get [as UglifyJsPlugin] (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/webpack/lib/webpack.js:174:10)
    at Object.<anonymous> (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/build/webpack.config.js:106:25)
    at Module._compile (/Users/tugenhua/工作文檔/18年項目/xd-f2e-tyr/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)

解決方案:

1. webpack內置的JS壓縮插件不能使用了,可以安裝uglifyjs-webpack-plugin插件,使用同其他非內置插件;

2. --mode production 表示生產環境,只要配置在package.json的script里面 js自動就壓縮了

注意:Uglify是壓縮js,現在已經不需要了,只需要在script里面寫成 "build": "webpack --mode production", 就自動壓縮了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM