vue-cli2.0中的方法

1.安装插件

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

2.修改webpack.prod.conf.js配置文件

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-cli3.0中的方法

1.安装babel插件

cnpm i babel-plugin-transform-remove-console -D

2.修改babel.config.js文件如下

const plugins = ['transform-remove-strict-mode'];
if (process.env.NODE_ENV === 'production' && process.env.VUE_APP_OpenLog == 0) {
  plugins.push('transform-remove-console');
}
module.exports = {
  presets: [
    [
      '@vue/app',
      {
        polyfills: ['es6.promise', 'es6.symbol']
      }
    ]
  ],
  ignore: ['./src/assets/js/mui.js'],
  plugins: plugins
};
Logo

前往低代码交流专区

更多推荐