UglifyJs配合webpack打包报Unexpected token: keyword const
Author:zhoulujun Date:
UglifyJS Webpack Plugin插件用来缩小(压缩优化)js文件,以及移除console debuger等,配置如下:
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
drop_console: true,//console
pure_funcs: ['console.log']//移除console }
},
sourceMap: config.build.productionSourceMap,
parallel: true
})
但是,缺报错了
因为:UglifyJS 不能识别 const语法。
是UglifyJS不支持ES6的语法。
发现uglifyjs-webpack-plugin 2.0版本的Release日志中,明确提示重新切换回到uglify-js,因为uglify-es被废弃了,如果需要ES6代码压缩,请使用terser-webpack-plugin
只有使用 terser-webpack-plugin 替换 uglifyjs-webpack-plugin 进行代码压缩。
使用 TerserPlugin 替换 UglifyJsPlugin , terserOptions 替换 uglifyOptions
其他参数基本一致。
修改后的配置如下:
new TerserPlugin({
terserOptions: {
compress: {
// warnings: false,
drop_debugger: true,
drop_console: true
}
},
sourceMap: false,
parallel: true
})
参考文章:
https://blog.csdn.net/meifannao789456/article/details/104793275/
转载本站文章《UglifyJs配合webpack打包报Unexpected token: keyword const》,
请注明出处:https://www.zhoulujun.cn/html/tools/Bundler/webpack/2019_1129_8552.html