umbrella22

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

......@@ -13,7 +13,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader')
const HappyPack = require('happypack')
const HappyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length })
......@@ -85,6 +84,8 @@ let rendererConfig = {
use: {
loader: 'vue-loader',
options: {
cacheDirectory: 'node_modules/.cache/vue-loader',
cacheIdentifier: '7270960a',
extractCSS: process.env.NODE_ENV === 'production',
loaders: {
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
......@@ -172,7 +173,6 @@ let rendererConfig = {
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HardSourceWebpackPlugin(),
new HappyPack({
id: 'HappyRendererBabel',
loaders: [{
......@@ -238,11 +238,19 @@ if (process.env.NODE_ENV === 'production') {
new TerserPlugin({
test: /\.js(\?.*)?$/i,
extractComments: false,
cache: false,
cache: true,
sourceMap: false,
terserOptions: {
warnings: false,
compress: {
hoist_funs: false,
hoist_props: false,
hoist_vars: false,
inline: false,
loops: false,
dead_code: true,
booleans: true,
if_return: true,
warnings: false,
drop_console: true,
drop_debugger: true,
......
此文件的差异太大,无法显示。
......@@ -76,43 +76,44 @@
"electron-updater": "^4.3.1",
"element-ui": "^2.13.2",
"express": "^4.17.1",
"fs-extra": "^9.0.0",
"fs-extra": "^9.0.1",
"js-cookie": "^2.2.1",
"nedb": "^1.8.0",
"nprogress": "^0.2.0",
"vue": "^2.6.11",
"vue-electron": "^1.0.6",
"vue-router": "^3.1.6",
"vue-router": "^3.3.2",
"vuex": "^3.4.0",
"vuex-electron": "^1.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-do-expressions": "^7.8.3",
"@babel/plugin-proposal-export-default-from": "^7.8.3",
"@babel/plugin-proposal-export-namespace-from": "^7.8.3",
"@babel/plugin-proposal-function-bind": "^7.8.3",
"@babel/plugin-proposal-function-sent": "^7.8.3",
"@babel/plugin-proposal-json-strings": "^7.8.3",
"@babel/plugin-proposal-logical-assignment-operators": "^7.8.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-numeric-separator": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/plugin-proposal-pipeline-operator": "^7.8.3",
"@babel/plugin-proposal-throw-expressions": "^7.8.3",
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "^7.10.1",
"@babel/plugin-proposal-decorators": "^7.10.1",
"@babel/plugin-proposal-do-expressions": "^7.10.1",
"@babel/plugin-proposal-export-default-from": "^7.10.1",
"@babel/plugin-proposal-export-namespace-from": "^7.10.1",
"@babel/plugin-proposal-function-bind": "^7.10.1",
"@babel/plugin-proposal-function-sent": "^7.10.1",
"@babel/plugin-proposal-json-strings": "^7.10.1",
"@babel/plugin-proposal-logical-assignment-operators": "^7.10.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.1",
"@babel/plugin-proposal-numeric-separator": "^7.10.1",
"@babel/plugin-proposal-optional-chaining": "^7.10.1",
"@babel/plugin-proposal-pipeline-operator": "^7.10.1",
"@babel/plugin-proposal-throw-expressions": "^7.10.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/polyfill": "^7.8.7",
"@babel/preset-env": "^7.9.6",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.6",
"@babel/plugin-syntax-import-meta": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.10.1",
"@babel/polyfill": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@babel/register": "^7.10.1",
"@babel/runtime": "^7.10.2",
"ajv": "^6.12.2",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.1.0",
"babel-minify-webpack-plugin": "^0.3.1",
"cache-loader": "^4.1.0",
"cfonts": "^2.8.2",
"chalk": "^4.0.0",
"copy-webpack-plugin": "^5.1.1",
......@@ -133,7 +134,6 @@
"eslint-plugin-standard": "^4.0.0",
"file-loader": "^6.0.0",
"happypack": "^5.0.1",
"hard-source-webpack-plugin": "^0.13.1",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "0.9.0",
"multispinner": "^0.2.1",
......@@ -144,7 +144,7 @@
"split2": "^3.1.1",
"style-loader": "^1.2.1",
"svg-sprite-loader": "^4.3.0",
"terser-webpack-plugin": "^3.0.1",
"terser-webpack-plugin": "^3.0.3",
"through2-filter": "^3.0.0",
"url-loader": "^4.1.0",
"vue-html-loader": "^1.2.4",
......
import router from './router'
import store from './store'
import Performance from '@/tools/performance'
var end = null
const whiteList = ['/login'] // 不重定向白名单
router.beforeEach((to, from, next) => {
end = Performance.startExecute(`${from.path} => ${to.path} 路由耗时`) /// 路由性能监控
if (store.getters.token) {
if (to.path === '/login') {
next({ path: '/' })
......@@ -16,6 +20,9 @@ router.beforeEach((to, from, next) => {
next('/login')
}
}
setTimeout(() => {
end()
}, 0)
})
router.afterEach(() => { })
......
/**
* 性能工具
* 1. 计算方法执行时间
* @returns {void}
* @date 2019-11-29
*/
import Timer from './timer'
class Performance {
/**
* 计算情况
* @returns {Function} 执行返回值获取时间信息
* @date 2019-11-29
*/
startExecute (name = '') {
const timer = Timer.start()
const usedJSHeapSize = this.getMemoryInfo().usedJSHeapSize
return (name2 = '') => {
const executeTime = timer.stop()
const endMemoryInfo = this.getMemoryInfo()
console.log('%cPerformance%c \n1. 执行方法:%c%s%c\n2. 执行耗时: %c%sms%c \n3. 内存波动:%sB \n4. 已分配内存: %sMB \n5. 已使用内存:%sMB \n6. 剩余内存: %sMB',
'padding: 2px 4px 2px 4px; background-color: #4caf50; color: #fff; border-radius: 4px;', '',
'color: #ff6f00', `${name} ${name2}`, '',
'color: #ff6f00', executeTime, '',
endMemoryInfo.usedJSHeapSize - usedJSHeapSize,
this.toMBSize(endMemoryInfo.jsHeapSizeLimit),
this.toMBSize(endMemoryInfo.usedJSHeapSize),
this.toMBSize(endMemoryInfo.totalJSHeapSize)
)
}
}
/**
* 获取内存信息
* @returns {void}
* @date 2019-11-29
*/
getMemoryInfo () {
let memoryInfo = {}
if (window.performance && window.performance.memory) {
memoryInfo = window.performance.memory
}
return memoryInfo
}
/**
* 转化为MB
* @returns {void}
* @date 2019-11-29
*/
toMBSize (byteSize) {
return (byteSize / (1024 * 1024)).toFixed(1)
}
}
export default new Performance()
/* eslint-disable no-return-assign */
/**
* 计时器
* 支持链式调用
* timeout()
* .then(()=>{
* return inTheEnd();
* })
* .then(()=>{
* return inTheEnd();
* });
*
* @date 2019-11-25
*/
class Timer {
/**
* 延时操作
* @returns {void}
* @date 2019-11-25
*/
timeout (interval, args) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(args)
}, interval)
})
}
/**
* 等待代码片段执行完毕后再执行
* @returns {void}
* @date 2019-11-25
*/
inTheEnd () {
return this.timeout(0)
}
/**
* 循环定时, 执行回调后再继续下一轮循环
* @param {Number} interval 执行间隔
* @param {Function} [callback] 回调
* @returns {Object}
* @date 2019-11-25
*/
interval (interval, callback) {
this.timeout(interval)
.then(() => {
typeof callback === 'function' &&
callback() !== false &&
this.interval(interval, callback)
})
return { then: c => callback = c }
}
/**
* 计时,单位毫秒
* @returns {void}
* @date 2019-11-29
*/
start () {
const startDate = new Date()
return {
stop () {
const stopDate = new Date()
return stopDate.getTime() - startDate.getTime()
}
}
}
}
export default new Timer()