今天再從新配置老項目node打包環境的時候遇到了一個問題。css
在打包的時候報:node
TypeError: Cannot read property 'compilation' of undefined 錯誤。
很明顯,這是node一些包的版本對應不上的問題。。。webpack
一、首先定位到uglifyjs-webpack-plugin中的index.js文件中,將項目中的該包升級或者降級到1.0.0版本 npm i uglifyjs-webpack-plugin@1.0.0 --save 二、而後定位到optimize-css-assets-webpack-plugin\node_modules\last-call-webpack-plugin\src\index.js文件報錯 將項目中的該包(optimize-css-assets-webpack-plugin)升級或者降級到2.0.0版本 npm i optimize-css-assets-webpack-plugin@2 --save 三、這個時候報缺乏"cssnano"包,直接安裝上便可(到這一步就成功了) 四、最後附上醜化壓縮配置 // CSS壓縮醜化 const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin'); // JavaScript壓縮醜化 const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); new UglifyJsPlugin({ uglifyOptions: { compress: { warnings: false, drop_debugger: true, drop_console: true } }, sourceMap: true, parallel: true }), new OptimizeCSSPlugin({ cssProcessorOptions: { safe: true, map: { inline: false } } }),
原文:https://blog.csdn.net/u011169370/article/details/83346176web