vue-cli 3.0 打包后删除 console.log

一、babel-plugin-transform-remove-console

1.先下载

npm install babel-plugin-transform-remove-console --save-dev

2. 在 babel.consig.js 中配置

if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "sit") {
  plugins.push("transform-remove-console");
}

二、terser-webpack-plugin

1.先下载

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

2. vue.config.js 中引入

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

config.plugins.push(
  //去掉打包之后的打印
  new TerserPlugin({
    terserOptions: {
      ecma: undefined,
      warnings: false,
      parse: {},
      compress: {
        drop_console: true,
        drop_debugger: false,
        pure_funcs: ["console.log"], // 移除console
      },
    },
  })
);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容