安裝 uglifyjs-webpack-plugin 插件:
npm i uglifyjs-webpack-plugin@1.0.0 --save
可以在?nuxt.config.js?中的?build->plugins?中添加?uglifyjs-webpack-plugin?插件萤悴,里面有配置可以去掉 console 信息毁靶。
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
?build: {
? ?plugins: [
? ? ?new UglifyJsPlugin({
? ? ? ?uglifyOptions: {
? ? ? ? ?compress: {
? ? ? ? ? ?warnings: false,
? ? ? ? ? ?drop_console: true? // 設(shè)置false 就是 開啟 console.log
? ? ? ? ?},
? ? ? ? ?mangle: {
? ? ? ? ? ?safari10: true
? ? ? ? ?}
? ? ? ?},
? ? ? ?sourceMap: true,
? ? ? ?cache: true,
? ? ? ?parallel: true
? ? ?})
? ?]
?}
}
最后 npm run build打包? 成功了。
作者在 安裝插件的時候 直接發(fā)現(xiàn)遇到報錯 Cannot read property 'compilation' of undefined
所以直接安裝了?1.0.0 版本。
下面是一些特殊報錯和解決辦法: 作者反正沒遇到混驰。
很明顯,這是node一些包的版本對應(yīng)不上的問題宵喂。
1蜂莉、首先定位到?uglifyjs-webpack-plugin?中的?index.js?文件中,將項(xiàng)目中的該包升級或者降級到1.0.0版本
npm i uglifyjs-webpack-plugin@1.0.0 --save
2欣硼、然后定位到?optimize-css-assets-webpack-plugin\node_modules\last-call-webpack-plugin\src\index.js?文件報錯
將項(xiàng)目中的該包(optimize-css-assets-webpack-plugin)升級或者降級到2.0.0版本
npm i optimize-css-assets-webpack-plugin@2 --save
3题翰、這個時候報缺少?cssnano?包,直接安裝上即可
npm i cssnano --save
此刻 該問題完美解決诈胜。