打包后的代码段:app.js

vue-cli 代码打包: 压缩+混淆+去注释

找到文件夹 build/webpack.pro.conf.js

  • 在UglifyJsPlugin 插件中39行加入两行代码
  1. drop_console: true,
  2. pure_funcs: [‘console.log’]
    new UglifyJsPlugin({
      uglifyOptions: {
        compress: {
          warnings: false,
          //drop_console  传递true以放弃对控制台的调用。*功能
          drop_console: true,
          // pure_funces 禁用console.log函数
          pure_funcs: ['console.log']
        },
      },
      sourceMap: config.build.productionSourceMap,
      parallel: true
    }),

参考文档

UglifyJS插件官方文档

UglifyJS插件选项配置

相关文章:

  • 2022-01-18
  • 2021-07-10
  • 2022-12-23
  • 2021-07-13
  • 2021-07-18
  • 2021-05-26
  • 2021-07-13
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2021-08-28
  • 2021-12-04
  • 2022-01-21
  • 2022-12-23
相关资源
相似解决方案