webpack4.x使用UglifyJS出错问题
栏目: JavaScript · 发布时间: 6年前
内容简介:webpack中使用UglifyJS压缩代码时,出现如下错误:在webpack中,添加如下配置:
webpack中使用UglifyJS压缩代码时,出现如下错误:
ERROR in admin.b996c1979478ca946548.bundle.js from UglifyJs Unexpected token: keyword (const) [src/components/Alerts.vue:36,0][admin.b996c1979478ca946548.bundle.js:740,6]
原因
- 从出错信息来看,是UglifyJS不支持ES6的语法。理论上不应该啊…
-
于是Google之,发现uglifyjs-webpack-plugin 2.0版本的Release日志中,明确提示重新切换回到 uglify-js
,因为uglify-es被废弃了,如果需要ES6代码压缩,请使用 terser-webpack-plugin
解决
- 方法一:使用Babel将ES6转换为ES5。
-
方法一:安装并使用[terser-webpack-plugin]:( https://github.com/webpack-contrib/terser-webpack-plugin
)
$ npm install terser-webpack-plugin --save-dev
在webpack中,添加如下配置:
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
//...
optimization: {
minimizer: [new TerserPlugin()]
}
};
参考
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 使用css时,可能会出错的两个地方
- MyBatis Batch Update Exception使用foreach批量update出错
- 如何避免空指针出错?
- 如何避免特效渲染出错?
- OmniROM:“Flex checkpolicy”出错
- Python安装软件包出错
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Practical Algorithms for Programmers
Andrew Binstock、John Rex / Addison-Wesley Professional / 1995-06-29 / USD 39.99
Most algorithm books today are either academic textbooks or rehashes of the same tired set of algorithms. Practical Algorithms for Programmers is the first book to give complete code implementations o......一起来看看 《Practical Algorithms for Programmers》 这本书的介绍吧!