From eb9d1e823863844d4109bf3969f96766105cba4a Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Sun, 27 Feb 2022 13:31:19 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=90=8C=E6=AD=A5=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/info.ts | 85 ++++++++++++++++++++++++++++ build/plugins.ts | 2 + package.json | 7 ++- pnpm-lock.yaml | 59 +++++++++++++++---- src/layout/components/setting/index.vue | 4 +- src/layout/components/sidebar/breadCrumb.vue | 2 +- src/layout/components/tag/index.vue | 2 +- src/plugins/i18n/index.ts | 2 +- src/router/index.ts | 2 +- src/router/utils.ts | 12 ++-- src/store/modules/multiTags.ts | 2 +- src/store/modules/permission.ts | 2 +- src/style/element-plus.scss | 11 ---- 13 files changed, 155 insertions(+), 37 deletions(-) create mode 100644 build/info.ts diff --git a/build/info.ts b/build/info.ts new file mode 100644 index 0000000..95a8aa0 --- /dev/null +++ b/build/info.ts @@ -0,0 +1,85 @@ +import { readdir, stat } from "fs"; +import type { Plugin } from "vite"; +import dayjs, { Dayjs } from "dayjs"; +import { sum } from "lodash-unified"; +import duration from "dayjs/plugin/duration"; +import { green, blue, bold } from "picocolors"; +dayjs.extend(duration); + +const staticPath = "dist"; +const fileListTotal: number[] = []; + +const recursiveDirectory = (folder: string, callback: Function): void => { + readdir(folder, (err, files: string[]) => { + if (err) throw err; + let count = 0; + const checkEnd = () => { + ++count == files.length && callback(); + }; + files.forEach((item: string) => { + stat(folder + "/" + item, async (err, stats) => { + if (err) throw err; + if (stats.isFile()) { + fileListTotal.push(stats.size); + checkEnd(); + } else if (stats.isDirectory()) { + recursiveDirectory(`${staticPath}/${item}/`, checkEnd); + } + }); + }); + files.length === 0 && callback(); + }); +}; + +const formatBytes = (a: number, b?: number): string => { + if (0 == a) return "0 Bytes"; + const c = 1024, + d = b || 2, + e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], + f = Math.floor(Math.log(a) / Math.log(c)); + return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f]; +}; + +export function viteBuildInfo(): Plugin { + let config: { command: string }; + let startTime: Dayjs; + let endTime: Dayjs; + return { + name: "vite:buildInfo", + configResolved(resolvedConfig: { command: string }) { + config = resolvedConfig; + }, + buildStart() { + if (config.command === "build") { + startTime = dayjs(new Date()); + } + }, + closeBundle() { + if (config.command === "build") { + console.log( + bold( + green( + `👏欢迎使用${blue( + "[vue-pure-admin]" + )},如果您感觉不错,记得点击后面链接给个star哦💖 https://github.com/xiaoxian521/vue-pure-admin` + ) + ) + ); + endTime = dayjs(new Date()); + recursiveDirectory(staticPath, () => { + console.log( + bold( + green( + `恭喜打包完成🎉(总用时${dayjs + .duration(endTime.diff(startTime)) + .format("mm分ss秒")},打包后的大小为${formatBytes( + sum(fileListTotal) + )})` + ) + ) + ); + }); + } + } + }; +} diff --git a/build/plugins.ts b/build/plugins.ts index 1cbd6a2..aceb57d 100644 --- a/build/plugins.ts +++ b/build/plugins.ts @@ -1,4 +1,5 @@ import vue from "@vitejs/plugin-vue"; +import { viteBuildInfo } from "./info"; import svgLoader from "vite-svg-loader"; import legacy from "@vitejs/plugin-legacy"; import vueJsx from "@vitejs/plugin-vue-jsx"; @@ -20,6 +21,7 @@ export function getPluginsList(command, VITE_LEGACY) { WindiCSS(), // 线上环境删除console removeConsole(), + viteBuildInfo(), // 修改layout文件夹下的文件时自动重载浏览器 解决 https://github.com/xiaoxian521/vue-pure-admin/issues/170 liveReload(["src/layout/**/*", "src/router/**/*"]), // 自定义主题 diff --git a/package.json b/package.json index e27edc9..5309663 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,11 @@ "axios": "^0.25.0", "css-color-function": "^1.3.3", "dayjs": "^1.10.7", - "element-plus": "^2.0.2", + "element-plus": "^2.0.3", "element-resize-detector": "^1.2.3", "js-cookie": "^3.0.1", "lodash-es": "^4.17.21", + "lodash-unified": "^1.0.2", "mitt": "^3.0.0", "mockjs": "^1.1.0", "nprogress": "^0.2.0", @@ -65,6 +66,7 @@ "@iconify/vue": "^3.1.3", "@types/element-resize-detector": "1.1.3", "@types/js-cookie": "^3.0.1", + "@types/lodash-es": "^4.17.6", "@types/mockjs": "1.0.3", "@types/node": "14.14.14", "@types/nprogress": "0.2.0", @@ -84,6 +86,7 @@ "eslint-plugin-vue": "^8.4.1", "husky": "7.0.2", "lint-staged": "11.1.2", + "picocolors": "^1.0.0", "postcss": "^8.4.6", "postcss-html": "^1.3.0", "postcss-import": "14.0.0", @@ -91,7 +94,7 @@ "prettier": "^2.5.1", "pretty-quick": "3.1.1", "rimraf": "3.0.2", - "rollup-plugin-visualizer": "^5.5.4", + "rollup-plugin-visualizer": "^5.6.0", "sass": "^1.49.0", "sass-loader": "^12.4.0", "stylelint": "^14.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e1d2af4..478d593 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,7 @@ specifiers: "@iconify/vue": ^3.1.3 "@types/element-resize-detector": 1.1.3 "@types/js-cookie": ^3.0.1 + "@types/lodash-es": ^4.17.6 "@types/mockjs": 1.0.3 "@types/node": 14.14.14 "@types/nprogress": 0.2.0 @@ -32,7 +33,7 @@ specifiers: cross-env: 7.0.3 css-color-function: ^1.3.3 dayjs: ^1.10.7 - element-plus: ^2.0.2 + element-plus: ^2.0.3 element-resize-detector: ^1.2.3 eslint: ^8.8.0 eslint-plugin-prettier: ^4.0.0 @@ -41,10 +42,12 @@ specifiers: js-cookie: ^3.0.1 lint-staged: 11.1.2 lodash-es: ^4.17.21 + lodash-unified: ^1.0.2 mitt: ^3.0.0 mockjs: ^1.1.0 nprogress: ^0.2.0 path: ^0.12.7 + picocolors: ^1.0.0 pinia: ^2.0.11 postcss: ^8.4.6 postcss-html: ^1.3.0 @@ -57,7 +60,7 @@ specifiers: responsive-storage: ^1.0.11 rgb-hex: ^4.0.0 rimraf: 3.0.2 - rollup-plugin-visualizer: ^5.5.4 + rollup-plugin-visualizer: ^5.6.0 sass: ^1.49.0 sass-loader: ^12.4.0 stylelint: ^14.3.0 @@ -91,10 +94,11 @@ dependencies: axios: 0.25.0 css-color-function: 1.3.3 dayjs: 1.10.7 - element-plus: 2.0.2_vue@3.2.31 + element-plus: 2.0.3_1a412d14def5ff5ca1122000e4bee666 element-resize-detector: 1.2.4 js-cookie: 3.0.1 lodash-es: 4.17.21 + lodash-unified: 1.0.2_f567d1d3c0c6a67669f03af7a1aa4dad mitt: 3.0.0 mockjs: 1.1.0 nprogress: 0.2.0 @@ -119,6 +123,7 @@ devDependencies: "@iconify/vue": 3.1.3_vue@3.2.31 "@types/element-resize-detector": 1.1.3 "@types/js-cookie": 3.0.1 + "@types/lodash-es": 4.17.6 "@types/mockjs": 1.0.3 "@types/node": 14.14.14 "@types/nprogress": 0.2.0 @@ -138,6 +143,7 @@ devDependencies: eslint-plugin-vue: 8.4.1_eslint@8.9.0 husky: 7.0.2 lint-staged: 11.1.2 + picocolors: 1.0.0 postcss: 8.4.6 postcss-html: 1.3.0 postcss-import: 14.0.0_postcss@8.4.6 @@ -145,7 +151,7 @@ devDependencies: prettier: 2.5.1 pretty-quick: 3.1.1_prettier@2.5.1 rimraf: 3.0.2 - rollup-plugin-visualizer: 5.5.4 + rollup-plugin-visualizer: 5.6.0 sass: 1.49.7 sass-loader: 12.6.0_sass@1.49.7 stylelint: 14.5.0 @@ -1098,6 +1104,22 @@ packages: } dev: true + /@types/lodash-es/4.17.6: + resolution: + { + integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg== + } + dependencies: + "@types/lodash": 4.14.179 + dev: true + + /@types/lodash/4.14.179: + resolution: + { + integrity: sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w== + } + dev: true + /@types/minimatch/3.0.5: resolution: { @@ -2805,10 +2827,10 @@ packages: } dev: true - /element-plus/2.0.2_vue@3.2.31: + /element-plus/2.0.3_1a412d14def5ff5ca1122000e4bee666: resolution: { - integrity: sha512-URjC0HwwiqtlLxqTmHXQ31WXrdAq4ChWyyn52OcQs3PRsnMPfahGVq2AWnfzzlzlhVeI5lY3HQiuB1zDathS+g== + integrity: sha512-k+b4V4sGmgOpOYjrAWyp0k+N1mVaIZQ9LpbXWvmJNzE+j21DYOe9m1zGn5mFDPgeLOZcUS7QzzwYAommhwFj0g== } peerDependencies: vue: ^3.2.0 @@ -2821,7 +2843,7 @@ packages: dayjs: 1.10.7 lodash: 4.17.21 lodash-es: 4.17.21 - lodash-unified: 1.0.1_lodash-es@4.17.21+lodash@4.17.21 + lodash-unified: 1.0.2_da03a4540fbd16bbaafbb96724306afd memoize-one: 6.0.0 normalize-wheel-es: 1.1.1 vue: 3.2.31 @@ -4388,20 +4410,35 @@ packages: } dev: false - /lodash-unified/1.0.1_lodash-es@4.17.21+lodash@4.17.21: + /lodash-unified/1.0.2_da03a4540fbd16bbaafbb96724306afd: resolution: { - integrity: sha512-Py+twfpWn+2dFQWCuGcp21WiQRwZwnm1cyE3piSt/VtBVKVyxlR58WgOVRzXtmdmDRGJKH8F8GPaA29WK/yK8g== + integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g== } peerDependencies: "@types/lodash-es": "*" lodash: "*" lodash-es: "*" dependencies: + "@types/lodash-es": 4.17.6 lodash: 4.17.21 lodash-es: 4.17.21 dev: false + /lodash-unified/1.0.2_f567d1d3c0c6a67669f03af7a1aa4dad: + resolution: + { + integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g== + } + peerDependencies: + "@types/lodash-es": "*" + lodash: "*" + lodash-es: "*" + dependencies: + "@types/lodash-es": 4.17.6 + lodash-es: 4.17.21 + dev: false + /lodash.get/4.4.2: resolution: { integrity: sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= } dev: true @@ -5866,10 +5903,10 @@ packages: glob: 7.2.0 dev: true - /rollup-plugin-visualizer/5.5.4: + /rollup-plugin-visualizer/5.6.0: resolution: { - integrity: sha512-CJQFUuZ75S1daGEkk62UH7lL6UFCoP86Sn/iz4gXBdamdwFeD5nPGCHHXfXCrly/wNgQOYTH7cdcxk4+OG3Xjw== + integrity: sha512-CKcc8GTUZjC+LsMytU8ocRr/cGZIfMR7+mdy4YnlyetlmIl/dM8BMnOEpD4JPIGt+ZVW7Db9ZtSsbgyeBH3uTA== } engines: { node: ">=12" } hasBin: true diff --git a/src/layout/components/setting/index.vue b/src/layout/components/setting/index.vue index 6fe8f8e..77988b2 100644 --- a/src/layout/components/setting/index.vue +++ b/src/layout/components/setting/index.vue @@ -10,7 +10,7 @@ import { getCurrentInstance } from "vue"; import rgbHex from "rgb-hex"; -import { find } from "lodash-es"; +import { find } from "lodash-unified"; import { getConfig } from "/@/config"; import { useRouter } from "vue-router"; import panel from "../panel/index.vue"; @@ -111,7 +111,7 @@ function storageConfigureChange(key: string, val: T): void { function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) { const targetEl = target || document.body; let { className } = targetEl; - className = className.replace(clsName, ""); + className = className.replace(clsName, "").trim(); targetEl.className = flag ? `${className} ${clsName} ` : className; } diff --git a/src/layout/components/sidebar/breadCrumb.vue b/src/layout/components/sidebar/breadCrumb.vue index e8d4d59..09f7cf6 100644 --- a/src/layout/components/sidebar/breadCrumb.vue +++ b/src/layout/components/sidebar/breadCrumb.vue @@ -1,6 +1,6 @@