赞
踩
js/app.6ff5e7c3.js from Terser Unexpected token: keyword «const» [js/app.6ff5e7c3.js:1,4460] error js/chunk-2c925c54.8731960b.js from Terser Unexpected token: punc «(» [js/chunk-2c925c54.8731960b.js:1,1959] error js/chunk-3a55163c.6c8c81ab.js from Terser Unexpected token: operator «>» [js/chunk-3a55163c.6c8c81ab.js:1,5448] error js/chunk-56fb77e9.eb13d476.js from Terser Unexpected token: punc «(» [js/chunk-56fb77e9.eb13d476.js:1,1690]
TerserPlugin的配置参入改成如下
const path = require('path') const TerserPlugin = require('terser-webpack-plugin') module.exports = { /** * Webpack 配置 */ configureWebpack: () => ({ plugins: [], optimization: { minimizer: [ new TerserPlugin({ terserOptions: { ecma: undefined, parse: {}, compress: { drop_console: true, // 传true就是⼲掉所有的console.*这些函数的调⽤. drop_debugger: true, // ⼲掉那些debugger; pure_funcs: ['console.log'] // 如果你要⼲掉特定的函数⽐如console.info ,⼜想删掉后保留其参数中的副作⽤,那⽤pure_funcs来处理 }, mangle: true, // Note `mangle.properties` is `false` by default. module: false, // Deprecated output: null, format: null, toplevel: false, nameCache: null, ie8: false, keep_classnames: undefined, keep_fnames: false, safari10: false } }) ] } }), }
原先报错的写法
const path = require('path') const TerserPlugin = require('terser-webpack-plugin') module.exports = { /** * Webpack 配置 */ configureWebpack: () => ({ plugins: [], optimization: { minimizer: [ new TerserPlugin({ minify: (file, sourceMap) => { const uglifyJsOptions = { compress: { drop_console: true, drop_debugger: true } } if (sourceMap) { uglifyJsOptions.sourceMap = { content: sourceMap } } return require('uglify-js').minify(file, uglifyJsOptions) } }) ] } }), }
我的webpack是版本5(cmd执行webpack -v)
webpack: 5.72.1
terser-webpack-plugin官网:https://webpack.docschina.org/plugins/terser-webpack-plugin/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。