Solve the error reported by UglifyJs during iview packaging, iviewuglifyjs

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.