vue 3.0 打包后 禁止在浏览器输出 console 等

1.打开 vue.config.js 把下面内容复制 pure_funcs种配置你要移除 的项

module.exports = {
//   打包后禁止在控制台输出console.log
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      config.plugins.push(
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: false,
              pure_funcs: ['console.log'] // 移除console
            }
          },
        }),
      )
    }
  },
}

2.在项目中 执行下面命令

npm install terser-webpack-plugin --save-dev

3、 在vue.config.js最顶部 粘贴以下代码

const TerserPlugin = require('terser-webpack-plugin');

如此简单

发布了13 篇原创文章 · 获赞 8 · 访问量 543

猜你喜欢

转载自blog.csdn.net/qq_41495998/article/details/103808758