Solve the error reported by UglifyJs during iview packaging, iviewuglifyjs
The run time is OK when npm run dev is used, but iview reports an error when npm run build is packaged,
As follows:
The reason is that es6 syntax is used in iview, but uglifyJs does not support it. Open the build/webpack. prod. conf. js file and you can see
// UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minifynew webpack.optimize.UglifyJsPlugin({compress: {warnings: false},sourceMap: config.build.productionSourceMap,parallel: true}),
It has been prompted that uglifyJs does not support es6.
Solution:
In webpack. base. conf. js, we first Add the following during js Compilation:
{test: /\.js$/,loader: 'babel-loader',include: [resolve('src'),resolve('test'),resolve('/node_modules/iview/src'),resolve('/node_modules/iview/packages')]},
First let the es6 Syntax of iview be converted by babel, and then build/webpack. prod. conf. in js, comment out the original uglifyJs and introduce external uglifyJs to compress and confuse Javascript. The Code is as follows:
// UglifyJs do not support ES6 +, you can also use babel-minify for better treeshaking: https://github.com/babel/minify// new webpack. optimize. uglifyJsPlugin ({// compress: {// warnings: false //}, // sourceMap: config. build. productionSourceMap, // parallel: true //}), new UglifyJsPlugin ({// use the newly introduced js compression tool parallel: true, uglifyOptions: {ie8: false, ecma: 6, warnings: false, mangle: true, // debug falseoutput: {comments: false, beautify: false, // debug true}, compress: {// do not output warning warnings: false when UglifyJs deletes unused code, // Delete All 'console' statements // also compatible with IE browser drop_console: true, // The nested variable collapse_vars defined only once: true, // extracts the static value performance_vars that appears multiple times but is not defined as a variable to reference: true ,}}}),
Of course, we must first introduce external plug-ins:
const UglifyJsPlugin =require('uglifyjs-webpack-plugin');
This can be solved.
The above article solves the error reported by UglifyJs during iview packaging. It is all the content that I shared with you. I hope to give you a reference and support for the customer's house.