vue-cli2.0中的方法
1.安装uglifyjs-webpack-plugin插件
npm install uglifyjs-webpack-plugin --save-dev

2.修改wenbpack.prod.config.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-plugin-transform-remove-console插件
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
};

 

 
 
posted on 2021-07-08 09:31  薇依  阅读(3106)  评论(0编辑  收藏  举报