vue2 + vue-cli4
webpack4會自帶terser-webpack-plugin插件。
vue.config.js文件
module.exports = {
// ...
chainWebpack(config) {
// ...
// 清除console
config.optimization.minimizer('terser').tap(options => {
options[0].terserOptions.compress.drop_console = true
return options
})
//...
}
//...
}
vue-cli chainwebpack配置
webpack 配置terser
chain鏈?zhǔn)脚渲?/p>
vue3 + vite
vite.config.ts文件
export default defineConfig({
// ...
esbuild: {
// ...
pure: ['console.log'], // 安全
// drop: ['console'], // esbuild官方說有風(fēng)險
// ...
},
// ...
})
Esbuild#drop:For example, you can mark console.log as pure using --pure:console.log. This will cause these API calls to be removed safely when minification is enabled.文章來源:http://www.zghlxwxcb.cn/news/detail-495764.html
Vite esbuild配置
esbuild prue配置項
esbuild drop配置項文章來源地址http://www.zghlxwxcb.cn/news/detail-495764.html
到了這里,關(guān)于vue2、vue-cli4以及vue3、vite打包去掉console.log的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!