vuecli4.5 去掉注释 console 等 vue.config.js


0311lc.com说:
chainWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {} else {
      // 为开发环境修改配置...
    }
    config.optimization.minimizer('terser').tap((args) => {
      args[0].terserOptions.compress.warnings = false

      args[0].terserOptions.compress.drop_console = true
      // args[0].terserOptions.compress.drop_debugger = true // 默认true

      args[0].terserOptions.compress.pure_funcs = ['console.*']
      // return [...args]
      return args
    })
  },
configureWebpack: (config) => {    
if (process.env.NODE_ENV === 'production') {      
      // 为生产环境修改配置...
      config.mode = 'production'
      // 将每个依赖包打包成单独的js文件
      const optimization = {
        runtimeChunk: 'single',
        splitChunks: {
          chunks: 'all',
          maxInitialRequests: Infinity,
          minSize: 20000, // 依赖包超过20000bit将被单独打包
          cacheGroups: {
            vendor: {
              test: /[\\/]node_modules[\\/]/,
              name (module) {
                // get the name. E.g. node_modules/packageName/not/this/part.js
                // or node_modules/packageName
                const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
                // npm package names are URL-safe, but some servers don't like @ symbols
                return `npm.${packageName.replace('@', '')}`
              }
            }
          }
        }
      }

      Object.assign(config, {
        optimization
      })

} else {      
  // 开发环境
  config.mode = 'development'
}
},
vue inspect --mode=production > output.js

 


发表评论

电子邮件地址不会被公开。 必填项已用*标注