vue-cli2.0和vue-cli3.0生产环境去除console

//vue-cli3.0 vue-config.js

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

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

module.exports = {

  configureWebpack: config => {

    config

      .optimization = {

        minimizer: [

          new TerserPlugin({

            terserOptions: {

              compress: {

                drop_console: true

              }

            }

          })

        ]

      }

  }

}

//vue-cli2.0 webpack.prod.conf.js

//npm install uglifyjs-webpack-plugin --save-dev

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

plugins: [

        // http://vuejs.github.io/vue-loader/en/workflow/production.html

        new webpack.DefinePlugin({

            'process.env': env

        }),

        new UglifyJsPlugin({

            uglifyOptions: {

                // include: /\/src/,

                compress: {

                    warnings: false,

                    drop_debugger: true, //自动删除debugger

                    drop_console: true //自动删除console.log

                }

            },

            sourceMap: config.build.productionSourceMap,

            parallel: true

        }),

......

你可能感兴趣的:(vue-cli2.0和vue-cli3.0生产环境去除console)