uglifyjs-webpack-plugin配置


項目使用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. 嘿嘿, 沒了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM