1.安装插件(此插件可移除js和vue文件中的注释、打印等信息)
npm install terser-webpack-plugin -D;
2.在vue.config.js中进行配置
const TerserPlugin = require("terser-webpack-plugin");
configureWebpack: {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
compress: {
drop_console: true,//移除所有console相关代码;
drop_debugger: true,//移除自动断点功能;
pure_funcs: ["console.log", "console.error"],//配置移除指定的指令,如console.log,alert等
},
format: {
comments: false,
},
},
extractComments: false,
})
]
}
}
本文介绍如何通过安装terser-webpack-plugin插件并配置vue.config.js,实现去除Vue项目中的console、debugger等console相关代码,以优化打包并保护敏感信息。
601

被折叠的 条评论
为什么被折叠?



