vue-cli3配置去掉console.log

在開發環境寫了很多console.log/info/debug,在生產環境需要去掉這些console。
webpack提供了刪除console的插件,在vue-cli3裏面是這樣用的:
首先安裝terser-webpack-plugin

cnpm install terser-webpack-plugin -D

vue.config.js中的配置

const TerserPlugin = require('terser-webpack-plugin');
// 去console插件

  configureWebpack: {
    optimization: {
      minimize: process.env.NODE_ENV === 'production',
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: true,
              pure_funcs: ['console.log'], // 移除console
            },
          },
        }),
      ],
    },
  },


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章