umbrella22

添加性能监控,修改渲染进程部分配置,升级依赖

...@@ -13,7 +13,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin') ...@@ -13,7 +13,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin')
13 const MiniCssExtractPlugin = require('mini-css-extract-plugin') 13 const MiniCssExtractPlugin = require('mini-css-extract-plugin')
14 const HtmlWebpackPlugin = require('html-webpack-plugin') 14 const HtmlWebpackPlugin = require('html-webpack-plugin')
15 const TerserPlugin = require('terser-webpack-plugin'); 15 const TerserPlugin = require('terser-webpack-plugin');
16 -const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
17 const { VueLoaderPlugin } = require('vue-loader') 16 const { VueLoaderPlugin } = require('vue-loader')
18 const HappyPack = require('happypack') 17 const HappyPack = require('happypack')
19 const HappyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length }) 18 const HappyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length })
...@@ -85,6 +84,8 @@ let rendererConfig = { ...@@ -85,6 +84,8 @@ let rendererConfig = {
85 use: { 84 use: {
86 loader: 'vue-loader', 85 loader: 'vue-loader',
87 options: { 86 options: {
87 + cacheDirectory: 'node_modules/.cache/vue-loader',
88 + cacheIdentifier: '7270960a',
88 extractCSS: process.env.NODE_ENV === 'production', 89 extractCSS: process.env.NODE_ENV === 'production',
89 loaders: { 90 loaders: {
90 sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1', 91 sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
...@@ -172,7 +173,6 @@ let rendererConfig = { ...@@ -172,7 +173,6 @@ let rendererConfig = {
172 }), 173 }),
173 new webpack.HotModuleReplacementPlugin(), 174 new webpack.HotModuleReplacementPlugin(),
174 new webpack.NoEmitOnErrorsPlugin(), 175 new webpack.NoEmitOnErrorsPlugin(),
175 - new HardSourceWebpackPlugin(),
176 new HappyPack({ 176 new HappyPack({
177 id: 'HappyRendererBabel', 177 id: 'HappyRendererBabel',
178 loaders: [{ 178 loaders: [{
...@@ -238,11 +238,19 @@ if (process.env.NODE_ENV === 'production') { ...@@ -238,11 +238,19 @@ if (process.env.NODE_ENV === 'production') {
238 new TerserPlugin({ 238 new TerserPlugin({
239 test: /\.js(\?.*)?$/i, 239 test: /\.js(\?.*)?$/i,
240 extractComments: false, 240 extractComments: false,
241 - cache: false, 241 + cache: true,
242 sourceMap: false, 242 sourceMap: false,
243 terserOptions: { 243 terserOptions: {
244 warnings: false, 244 warnings: false,
245 compress: { 245 compress: {
246 + hoist_funs: false,
247 + hoist_props: false,
248 + hoist_vars: false,
249 + inline: false,
250 + loops: false,
251 + dead_code: true,
252 + booleans: true,
253 + if_return: true,
246 warnings: false, 254 warnings: false,
247 drop_console: true, 255 drop_console: true,
248 drop_debugger: true, 256 drop_debugger: true,
......
此文件的差异太大,无法显示。
...@@ -76,43 +76,44 @@ ...@@ -76,43 +76,44 @@
76 "electron-updater": "^4.3.1", 76 "electron-updater": "^4.3.1",
77 "element-ui": "^2.13.2", 77 "element-ui": "^2.13.2",
78 "express": "^4.17.1", 78 "express": "^4.17.1",
79 - "fs-extra": "^9.0.0", 79 + "fs-extra": "^9.0.1",
80 "js-cookie": "^2.2.1", 80 "js-cookie": "^2.2.1",
81 "nedb": "^1.8.0", 81 "nedb": "^1.8.0",
82 "nprogress": "^0.2.0", 82 "nprogress": "^0.2.0",
83 "vue": "^2.6.11", 83 "vue": "^2.6.11",
84 "vue-electron": "^1.0.6", 84 "vue-electron": "^1.0.6",
85 - "vue-router": "^3.1.6", 85 + "vue-router": "^3.3.2",
86 "vuex": "^3.4.0", 86 "vuex": "^3.4.0",
87 "vuex-electron": "^1.0.3" 87 "vuex-electron": "^1.0.3"
88 }, 88 },
89 "devDependencies": { 89 "devDependencies": {
90 - "@babel/core": "^7.9.6", 90 + "@babel/core": "^7.10.2",
91 - "@babel/plugin-proposal-class-properties": "^7.8.3", 91 + "@babel/plugin-proposal-class-properties": "^7.10.1",
92 - "@babel/plugin-proposal-decorators": "^7.8.3", 92 + "@babel/plugin-proposal-decorators": "^7.10.1",
93 - "@babel/plugin-proposal-do-expressions": "^7.8.3", 93 + "@babel/plugin-proposal-do-expressions": "^7.10.1",
94 - "@babel/plugin-proposal-export-default-from": "^7.8.3", 94 + "@babel/plugin-proposal-export-default-from": "^7.10.1",
95 - "@babel/plugin-proposal-export-namespace-from": "^7.8.3", 95 + "@babel/plugin-proposal-export-namespace-from": "^7.10.1",
96 - "@babel/plugin-proposal-function-bind": "^7.8.3", 96 + "@babel/plugin-proposal-function-bind": "^7.10.1",
97 - "@babel/plugin-proposal-function-sent": "^7.8.3", 97 + "@babel/plugin-proposal-function-sent": "^7.10.1",
98 - "@babel/plugin-proposal-json-strings": "^7.8.3", 98 + "@babel/plugin-proposal-json-strings": "^7.10.1",
99 - "@babel/plugin-proposal-logical-assignment-operators": "^7.8.3", 99 + "@babel/plugin-proposal-logical-assignment-operators": "^7.10.1",
100 - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3", 100 + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.1",
101 - "@babel/plugin-proposal-numeric-separator": "^7.8.3", 101 + "@babel/plugin-proposal-numeric-separator": "^7.10.1",
102 - "@babel/plugin-proposal-optional-chaining": "^7.9.0", 102 + "@babel/plugin-proposal-optional-chaining": "^7.10.1",
103 - "@babel/plugin-proposal-pipeline-operator": "^7.8.3", 103 + "@babel/plugin-proposal-pipeline-operator": "^7.10.1",
104 - "@babel/plugin-proposal-throw-expressions": "^7.8.3", 104 + "@babel/plugin-proposal-throw-expressions": "^7.10.1",
105 "@babel/plugin-syntax-dynamic-import": "^7.8.3", 105 "@babel/plugin-syntax-dynamic-import": "^7.8.3",
106 - "@babel/plugin-syntax-import-meta": "^7.8.3", 106 + "@babel/plugin-syntax-import-meta": "^7.10.1",
107 - "@babel/plugin-transform-runtime": "^7.9.6", 107 + "@babel/plugin-transform-runtime": "^7.10.1",
108 - "@babel/polyfill": "^7.8.7", 108 + "@babel/polyfill": "^7.10.1",
109 - "@babel/preset-env": "^7.9.6", 109 + "@babel/preset-env": "^7.10.2",
110 - "@babel/register": "^7.9.0", 110 + "@babel/register": "^7.10.1",
111 - "@babel/runtime": "^7.9.6", 111 + "@babel/runtime": "^7.10.2",
112 "ajv": "^6.12.2", 112 "ajv": "^6.12.2",
113 "babel-eslint": "^9.0.0", 113 "babel-eslint": "^9.0.0",
114 "babel-loader": "^8.1.0", 114 "babel-loader": "^8.1.0",
115 "babel-minify-webpack-plugin": "^0.3.1", 115 "babel-minify-webpack-plugin": "^0.3.1",
116 + "cache-loader": "^4.1.0",
116 "cfonts": "^2.8.2", 117 "cfonts": "^2.8.2",
117 "chalk": "^4.0.0", 118 "chalk": "^4.0.0",
118 "copy-webpack-plugin": "^5.1.1", 119 "copy-webpack-plugin": "^5.1.1",
...@@ -133,7 +134,6 @@ ...@@ -133,7 +134,6 @@
133 "eslint-plugin-standard": "^4.0.0", 134 "eslint-plugin-standard": "^4.0.0",
134 "file-loader": "^6.0.0", 135 "file-loader": "^6.0.0",
135 "happypack": "^5.0.1", 136 "happypack": "^5.0.1",
136 - "hard-source-webpack-plugin": "^0.13.1",
137 "html-webpack-plugin": "^3.2.0", 137 "html-webpack-plugin": "^3.2.0",
138 "mini-css-extract-plugin": "0.9.0", 138 "mini-css-extract-plugin": "0.9.0",
139 "multispinner": "^0.2.1", 139 "multispinner": "^0.2.1",
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
144 "split2": "^3.1.1", 144 "split2": "^3.1.1",
145 "style-loader": "^1.2.1", 145 "style-loader": "^1.2.1",
146 "svg-sprite-loader": "^4.3.0", 146 "svg-sprite-loader": "^4.3.0",
147 - "terser-webpack-plugin": "^3.0.1", 147 + "terser-webpack-plugin": "^3.0.3",
148 "through2-filter": "^3.0.0", 148 "through2-filter": "^3.0.0",
149 "url-loader": "^4.1.0", 149 "url-loader": "^4.1.0",
150 "vue-html-loader": "^1.2.4", 150 "vue-html-loader": "^1.2.4",
......
1 import router from './router' 1 import router from './router'
2 import store from './store' 2 import store from './store'
3 +import Performance from '@/tools/performance'
3 4
5 +var end = null
4 const whiteList = ['/login'] // 不重定向白名单 6 const whiteList = ['/login'] // 不重定向白名单
5 router.beforeEach((to, from, next) => { 7 router.beforeEach((to, from, next) => {
8 + end = Performance.startExecute(`${from.path} => ${to.path} 路由耗时`) /// 路由性能监控
9 +
6 if (store.getters.token) { 10 if (store.getters.token) {
7 if (to.path === '/login') { 11 if (to.path === '/login') {
8 next({ path: '/' }) 12 next({ path: '/' })
...@@ -16,6 +20,9 @@ router.beforeEach((to, from, next) => { ...@@ -16,6 +20,9 @@ router.beforeEach((to, from, next) => {
16 next('/login') 20 next('/login')
17 } 21 }
18 } 22 }
23 + setTimeout(() => {
24 + end()
25 + }, 0)
19 }) 26 })
20 27
21 router.afterEach(() => { }) 28 router.afterEach(() => { })
......
1 +/**
2 + * 性能工具
3 + * 1. 计算方法执行时间
4 + * @returns {void}
5 + * @date 2019-11-29
6 + */
7 +import Timer from './timer'
8 +class Performance {
9 + /**
10 + * 计算情况
11 + * @returns {Function} 执行返回值获取时间信息
12 + * @date 2019-11-29
13 + */
14 + startExecute (name = '') {
15 + const timer = Timer.start()
16 + const usedJSHeapSize = this.getMemoryInfo().usedJSHeapSize
17 + return (name2 = '') => {
18 + const executeTime = timer.stop()
19 + const endMemoryInfo = this.getMemoryInfo()
20 + console.log('%cPerformance%c \n1. 执行方法:%c%s%c\n2. 执行耗时: %c%sms%c \n3. 内存波动:%sB \n4. 已分配内存: %sMB \n5. 已使用内存:%sMB \n6. 剩余内存: %sMB',
21 + 'padding: 2px 4px 2px 4px; background-color: #4caf50; color: #fff; border-radius: 4px;', '',
22 + 'color: #ff6f00', `${name} ${name2}`, '',
23 + 'color: #ff6f00', executeTime, '',
24 + endMemoryInfo.usedJSHeapSize - usedJSHeapSize,
25 + this.toMBSize(endMemoryInfo.jsHeapSizeLimit),
26 + this.toMBSize(endMemoryInfo.usedJSHeapSize),
27 + this.toMBSize(endMemoryInfo.totalJSHeapSize)
28 + )
29 + }
30 + }
31 +
32 + /**
33 + * 获取内存信息
34 + * @returns {void}
35 + * @date 2019-11-29
36 + */
37 + getMemoryInfo () {
38 + let memoryInfo = {}
39 + if (window.performance && window.performance.memory) {
40 + memoryInfo = window.performance.memory
41 + }
42 + return memoryInfo
43 + }
44 +
45 + /**
46 + * 转化为MB
47 + * @returns {void}
48 + * @date 2019-11-29
49 + */
50 + toMBSize (byteSize) {
51 + return (byteSize / (1024 * 1024)).toFixed(1)
52 + }
53 +}
54 +
55 +export default new Performance()
1 +/* eslint-disable no-return-assign */
2 +/**
3 + * 计时器
4 + * 支持链式调用
5 + * timeout()
6 + * .then(()=>{
7 + * return inTheEnd();
8 + * })
9 + * .then(()=>{
10 + * return inTheEnd();
11 + * });
12 + *
13 + * @date 2019-11-25
14 + */
15 +class Timer {
16 + /**
17 + * 延时操作
18 + * @returns {void}
19 + * @date 2019-11-25
20 + */
21 + timeout (interval, args) {
22 + return new Promise((resolve) => {
23 + setTimeout(() => {
24 + resolve(args)
25 + }, interval)
26 + })
27 + }
28 +
29 + /**
30 + * 等待代码片段执行完毕后再执行
31 + * @returns {void}
32 + * @date 2019-11-25
33 + */
34 + inTheEnd () {
35 + return this.timeout(0)
36 + }
37 +
38 + /**
39 + * 循环定时, 执行回调后再继续下一轮循环
40 + * @param {Number} interval 执行间隔
41 + * @param {Function} [callback] 回调
42 + * @returns {Object}
43 + * @date 2019-11-25
44 + */
45 + interval (interval, callback) {
46 + this.timeout(interval)
47 + .then(() => {
48 + typeof callback === 'function' &&
49 + callback() !== false &&
50 + this.interval(interval, callback)
51 + })
52 + return { then: c => callback = c }
53 + }
54 +
55 + /**
56 + * 计时,单位毫秒
57 + * @returns {void}
58 + * @date 2019-11-29
59 + */
60 + start () {
61 + const startDate = new Date()
62 + return {
63 + stop () {
64 + const stopDate = new Date()
65 + return stopDate.getTime() - startDate.getTime()
66 + }
67 + }
68 + }
69 +}
70 +
71 +export default new Timer()