Browse Source

优化webpack配置

347617796@qq.com 3 years ago
parent
commit
326a5c774d

File diff suppressed because it is too large
+ 676 - 195
package-lock.json


+ 5 - 5
package.json

@@ -7,8 +7,7 @@
     "build": "vue-cli-service build",
     "lint": "vue-cli-service lint",
     "devbuild": "vue-cli-service build --mode development",
-    "prebuild": "vue-cli-service build --mode production",
-    "analyzer": "cross-env use_analyzer=true npm run serve"
+    "prebuild": "vue-cli-service build --mode production --report"
   },
   "dependencies": {
     "@wangeditor/editor": "^0.12.3",
@@ -21,6 +20,7 @@
     "echarts": "^4.9.0",
     "element-ui": "^2.13.2",
     "file-saver": "^2.0.5",
+    "imagemin-pngquant": "^9.0.2",
     "moment": "^2.29.0",
     "nprogress": "^0.2.0",
     "qrcodejs2": "0.0.2",
@@ -38,14 +38,14 @@
     "@vue/cli-plugin-vuex": "~4.4.0",
     "@vue/cli-service": "~4.4.0",
     "babel-eslint": "^10.1.0",
-    "compression-webpack-plugin": "^1.1.12",
     "eslint": "^6.7.2",
     "eslint-plugin-vue": "^6.2.2",
+    "image-webpack-loader": "^8.0.1",
     "sass": "^1.26.5",
     "sass-loader": "^8.0.2",
     "script-loader": "^0.7.2",
     "svg-sprite-loader": "^5.2.1",
-    "vue-template-compiler": "^2.6.11",
-    "webpack-bundle-analyzer": "^4.3.0"
+    "uglifyjs-webpack-plugin": "^2.2.0",
+    "vue-template-compiler": "^2.6.11"
   }
 }

+ 4 - 0
src/components/EmployeeSelector.vue

@@ -375,6 +375,7 @@ export default {
 			let list = this.employee_list;
 			if (userlist) {
 				list = [...userlist].filter(x => [...list].some(y => y.id === x.id));
+				employee_selected_list=[...userlist].filter(x => [...employee_selected_list].some(y => y.id === x.id));
 			}
 			list.map(item => {
 				item['checked'] = false;
@@ -385,6 +386,7 @@ export default {
 					}
 				}
 			});
+			this.employee_selected_list = employee_selected_list;
 			this.list = list;
 			this.table_loading = false;
 		},
@@ -430,6 +432,8 @@ export default {
 							}
 						}
 					});
+					employee_selected_list=[...employee].filter(x => [...employee_selected_list].some(y => y.id === x.id));
+					that.employee_selected_list = employee_selected_list;
 					that.list = userAll;
 				})
 				.finally(() => {

+ 0 - 2
src/components/bonusPointsPopup.vue

@@ -266,8 +266,6 @@
 				</span>
 			</div>
 		</el-dialog>
-		
-		
 	</div>
 </template>
 

+ 1 - 2
src/router/index.js

@@ -36,8 +36,7 @@ const routes = [{
 			{
 				path: '/award_punish',
 				name: '我奖扣的',
-				component: () => import( /* webpackChunkName: "award_punish" */
-					'@/views/abPoint/award_punish.vue'),
+				component: () => import( /* webpackChunkName: "award_punish" */'@/views/abPoint/award_punish.vue'),
 				meta: {
 					icon: 'icon-shezhi_zuzhijiagou',
 					groupCode: 'abPoint',

+ 0 - 2
src/views/abPoint/award_punish.vue

@@ -246,8 +246,6 @@
 
 <script>
 import EmployeeSelector from '@/components/EmployeeSelector.vue';
-import moment from 'moment';
-
 import bonusPointsPopup from '@/components/bonusPointsPopup';
 import Steps from '@/components/Steps'; 
 import {getToken,getCache } from '@/api/auth';

+ 10 - 5
src/views/common/rewardTaskAmend.vue

@@ -18,7 +18,7 @@
 					</el-form-item>
 					
 					<el-form-item label="指定规则">
-						 <el-switch  v-model="isSelectType"></el-switch>
+						 <el-switch  v-model="isSelectType" @change="isSelectTypeC"></el-switch>
 					</el-form-item>
 					<!-- 选择分类 -->
 					<el-form-item class="test_cascader_id" label="选择分类"	v-if="!isSelectType"
@@ -254,6 +254,7 @@ export default {
 				dept_ids: null
 			},
 			point_types: [],
+			arr:[],
 			// 审批人
 			reviewerName: null,
 			reviewer_not_select: [],
@@ -400,9 +401,13 @@ export default {
 			this.fileFun('', filtList)
 			if(this.rewardTaskAmendData.point_config.item_info){
 				let itemInfo = this.rewardTaskAmendData.point_config.item_info
-				this.formData.tree_echo = this.ruleChange(itemInfo.rule_id,[itemInfo.id])
+				// 获取规则的上级分类
+				this.arr=[itemInfo.id];
+				this.ruleChange(itemInfo.rule_id)
+				this.formData.tree_echo = this.arr
 				this.isSelectType=true;
 				this.$nextTick(_=>{
+					this.arr=[];
 					this.ruleItemChange(this.formData.tree_echo)
 				})
 			}else if(this.rewardTaskAmendData.rule_id){//指定了分类
@@ -449,11 +454,11 @@ export default {
 			}
 			return arr;
 		},
-		ruleChange(aid,att){
-			att.unshift(aid)
+		ruleChange(aid){
+			this.arr.unshift(aid);
 			let list = this.trees_ab.rule_tree.filter(x => x.id == aid)
 			if(list[0].pid == 0){
-				return att
+				return false
 			}else{
 				this.ruleChange(list[0].pid)
 			}

+ 18 - 13
src/views/common/temporaryTaskAmend.vue

@@ -12,7 +12,7 @@
 						<el-input type="textarea" rows="3" maxlength="20" show-word-limit v-model="formData.task_name" placeholder="请输入任务内容(限20字)"></el-input>
 					</el-form-item>
 					<el-form-item label="指定规则">
-						 <el-switch  v-model="isSelectType"></el-switch>
+						 <el-switch  v-model="isSelectType" @change="isSelectTypeActive"></el-switch>
 					</el-form-item>
 					<!-- 选择分类 -->
 					<el-form-item class="test_cascader_id" label="选择分类"	v-if="!isSelectType"
@@ -258,6 +258,8 @@ export default {
 				ahead_award_point_limit: null,
 			},
 			point_types: [],
+			arr:[],
+			
 			// 执行者
 			executorName: null,
 			show_employee_selector: false,
@@ -363,7 +365,7 @@ export default {
 		this.point_types = JSON.parse(localStorage.getItem('types'));
 	},
 	methods: {
-		isSelectTypeC(){
+		isSelectTypeActive(){
 			let item = this.formData;
 			this.max = 0;
 			this.min = 0;
@@ -436,13 +438,16 @@ export default {
 			})
 			this.fileList = filtList
 			this.fileFun('', filtList)
-			console.log(this.modifyData.point_config)
 			// 指定了规则
 			if(this.modifyData.point_config.item_info){
 				let itemInfo = this.modifyData.point_config.item_info
-				this.formData.tree_echo = this.ruleChange(itemInfo.rule_id,[itemInfo.id])
+				this.arr=[itemInfo.id];
+				// 获取规则的上级分类
+				this.ruleChange(itemInfo.rule_id)
+				this.formData.tree_echo = this.arr
 				this.isSelectType=true;
 				this.$nextTick(_=>{
+					this.arr=[];
 					this.ruleItemChange(this.formData.tree_echo);
 				})
 			}else if(this.modifyData.rule_id){//指定了分类
@@ -457,6 +462,15 @@ export default {
 			})
 
 		},
+		ruleChange(aid){
+			this.arr.unshift(aid);
+			let list = this.trees_ab.rule_tree.filter(x => x.id == aid)
+			if(list[0].pid == 0){
+				return false
+			}else{
+				this.ruleChange(list[0].pid)
+			}
+		},
 		returnRuleVal(rule_id,arr){
 			arr.unshift(rule_id)
 			let list = this.trees_ab.rule_tree.filter(x => x.id == rule_id)
@@ -475,15 +489,6 @@ export default {
 		handleClose(done) {
 			done();
 		},
-		ruleChange(aid,att){
-			att.unshift(aid)
-			let list = this.trees_ab.rule_tree.filter(x => x.id == aid)
-			if(list[0].pid == 0){
-				return att
-			}else{
-				this.ruleChange(list[0].pid)
-			}
-		},
 		deductionPoint(item){
 			if (this.modifyData.point_config[item] != '0') {
 				this.formData[item] = this.modifyData.point_config[item];

+ 12 - 24
src/views/set/framework.vue

@@ -351,6 +351,7 @@ export default {
 			newId: 0,
 			dirSupList: [],
 			selected_dirSup: { employee: [], dept: [] },
+			employeeAll:[],//人员列表
 		};
 	},
 	components: {
@@ -374,6 +375,7 @@ export default {
 		}
 	},
 	created() {
+		this.filtration();
 		this.getInfo();
 		this.getEmployee();
 		this.manageList();
@@ -465,7 +467,9 @@ export default {
 							}else{
 								this.dirSupervisor = {}
 							}
-							this.propList = this.nameStrList(employeeD.superior_list, 'name');
+							// 过滤已经离职人员
+							let sup=[...this.employeeAll].filter(x => [...employeeD.superior_list].some(y => y.id === x.id));
+							this.propList = this.nameStrList(sup, 'name');
 						}
 						this.messageMore = data
 					}
@@ -478,34 +482,13 @@ export default {
 			}).finally(() =>{
 				this.show_loading = false
 			})
-			// this.$axios('get', '/api/employee/info', { id: isId })
-			// .then(res => {
-			// 	if (res.data.code == 1) {
-			// 		let data = res.data.data
-			// 		if(data.employee_detail.dept_list){
-			// 			this.deptList = this.nameStrList(data.employee_detail.dept_list, 'dept_name');
-			// 		}
-			// 		if(data.employee_detail.superior_list){
-			// 			let employeeD = data.employee_detail
-			// 			if(employeeD.superior_id != 0){
-			// 				this.dirSupervisor = employeeD.superior_list.filter(x => x.id == employeeD.superior_id)[0]
-			// 				console.log(this.dirSupervisor)
-			// 			}
-			// 			this.propList = this.nameStrList(employeeD.superior_list, 'name');
-			// 		}
-			// 		this.messageMore = data
-			// 	}
-			// }).finally(()=>{
-			// 	this.show_loading = false
-			// })
 		},
 		setSuperior(row){
 			this.mangeId = row.id
-			let createData = {}
-			createData = this.manageData.filter(x => x.is_creator == 1)
+			let createData = this.manageData.filter(x => x.is_creator == 1);
 			let list = this.manageData.filter(x => x.id != row.id && x.is_creator != 1)
 			this.employeeList = list
-			let supList = row.employee_detail.superior_list
+			let supList =row.employee_detail.superior_list
 			if(createData[0]){
 				supList.forEach(item =>{
 					createData.some(arr =>{
@@ -519,6 +502,11 @@ export default {
 			this.selected_manage.employee = supList
 			this.manageScope_show = true
 		},
+		filtration() {
+		  this.$axios('get', '/api/employee/index', { dept_id: this.pid, page: 0, page_size: 3000,is_official:1 }).then(res => {
+			 this.employeeAll = res.data.data.list;
+		  }); 
+		},
 		dirSuperior(row){
 			this.dirSupList = row.employee_detail.superior_list
 			if(this.dirSupervisor.name){

+ 1 - 0
src/views/set/rule.vue

@@ -879,6 +879,7 @@ export default {
 		handleNodeClick(e) {
 			if(e.id){
 				var items = this.getItemData(e);
+				console.log(items,e.id)
 				this.selectItem = {
 					child: e.child,
 					id: e.id,

+ 90 - 21
vue.config.js

@@ -3,8 +3,8 @@ const path = require('path')
 function resolve(dir) {
 	return path.join(__dirname, dir)
 }
-const WebpackBundleAnalyzer = require('webpack-bundle-analyzer');
-const CompressionWebpackPlugin = require('compression-webpack-plugin')
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
+const DEV = process.env.NODE_ENV == 'production';
 module.exports = {
 	// 选项...
 	publicPath: './',
@@ -23,11 +23,19 @@ module.exports = {
 		disableHostCheck: true,
 	},
 	chainWebpack: (config) => {
-		// 配置可视化打包结构构成
-		if (process.env.use_analyzer) {
-			config.plugin('webpack-bundle-analyzer').use(WebpackBundleAnalyzer.BundleAnalyzerPlugin);
-		}
-
+		// 移除 prefetch 插件
+		config.plugins.delete('prefetch')
+		// 移除 preload 插件
+		config.plugins.delete('preload');
+		// ============压缩图片 start============
+		config.module
+			.rule('images')
+			.use('image-webpack-loader')
+			.loader('image-webpack-loader')
+			.options({bypassOnDebug: true})
+			.end()
+		// ============压缩图片 end============
+		
 		//配置 svg-sprite-loader
 		// 第一步:让其他svg loader不要对src/icons进行操作
 		config.module
@@ -49,20 +57,81 @@ module.exports = {
 			.end()
 	},
 	configureWebpack: config => {
-		let plugins = [
-			new CompressionWebpackPlugin({
-				filename: '[path].gz[query]',
-				algorithm: 'gzip',
-				test: new RegExp(
-					'\\.(' + ['js', 'css'].join('|') +
-					')$',
-				),
-				threshold: 10240,
-				minRatio: 0.8,
-			}),
-		]
-		if (process.env.NODE_ENV !== 'development') {
-			config.plugins = [...config.plugins, ...plugins]
+		config.plugins.push(
+			new UglifyJsPlugin({
+				uglifyOptions: {
+					//生产环境自动删除console
+					compress: {
+						drop_debugger: true,
+						drop_console: true,
+						pure_funcs: ['console.log']
+					}
+				},
+				sourceMap: false,
+				parallel: true
+			})
+		)
+		config.optimization.splitChunks = {
+			cacheGroups: {
+				vendors: {
+					chunks: 'all',
+					name: "chunk-vendors",
+					test: /[\\/]node_modules[\\/]/,
+					chunks: "initial",
+					priority: 2,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				elementUI: {
+					chunks: 'all',
+					name: "stabled-elementui",
+					test: /[\\/]node_modules[\\/]element-ui[\\/]/,
+					priority: 3,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				echarts: {
+					chunks: 'all',
+					name: "stabled-echarts",
+					test: /[\\/]node_modules[\\/]echarts[\\/]/,
+					priority: 4,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				vue: {
+					name: 'stabled-vue',
+					test: /[\\/]node_modules[\\/]vue[\\/]/,
+					chunks: "all",
+					priority: 5,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				vuex: {
+					name: 'stabled-vue',
+					test: /[\\/]node_modules[\\/]vuex[\\/]/,
+					chunks: "all",
+					priority: 6,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				'vue-router': {
+					name: 'stabled-vue',
+					test: /[\\/]node_modules[\\/]vue-router[\\/]/,
+					chunks: "all",
+					priority: 7,
+					reuseExistingChunk: true,
+					enforce: true
+				},
+				zrender: {
+					name: "stabled-zrender",
+					test: /[\\/]node_modules[\\/]zrender[\\/]/,
+					chunks: "all",
+					priority: 8,
+					reuseExistingChunk: true,
+					enforce: true
+				}
+			}
 		}
 	},
+
 }

Some files were not shown because too many files changed in this diff