uglifyjs-webpack-plugin配置

Posted on 2021-09-29 19:44  小小憨批儿  阅读(2542)  评论(0编辑  收藏  举报

项目使用vuecli3搭建,在vue.config.js文件中进行配置,主要配置了去除线上环境的打印信息。

  1. 首先安装插件, 执行命令
	npm install uglifyjs-webpack-plugin --save
  1. 配置插件
    vue.config.js
	/** 引入uglifyjs-webpack-plugin */
	const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
	/** 全局变量,当前环境 */
	const env = process.env.NODE_ENV;
	module.exports = {
	  ...
	  configureWebpack: config => {
		if (env === "production") {
			  /** 生产环境配置 */
			  config.mode = 'production';
			  /** 移除console */
			  config.optimization.minimizer.push(
				  new UglifyJsPlugin({
					  uglifyOptions: {
						  warnings: false,
						  compress: {
							  drop_console: true,
							  drop_debugger: true,
							  pure_funcs: ['console.log'] 
						  }
					  }
				  })
			  )
		  } else {
				/** 开发环境配置 */
				config.mode = "development";
		  }
		  Object.assign(config, {
			  name: '零信任后台管理系统',
			  resolve: {
				  alias: {
					  '@': resolve('src')
				  }
			  }
		  })
	  },
	  ...
	}
  1. 嘿嘿, 没了。

Copyright © 2024 小小憨批儿
Powered by .NET 8.0 on Kubernetes