diff --git a/build/info.ts b/build/info.ts index 7ef3f11f38..06006411d1 100644 --- a/build/info.ts +++ b/build/info.ts @@ -1,8 +1,8 @@ import type { Plugin } from "vite"; +import picocolors from "picocolors"; import dayjs, { Dayjs } from "dayjs"; -import utils from "@pureadmin/utils"; +import { getPackageSize } from "./utils"; import duration from "dayjs/plugin/duration"; -import { green, blue, bold } from "picocolors"; dayjs.extend(duration); export function viteBuildInfo(): Plugin { @@ -10,6 +10,7 @@ export function viteBuildInfo(): Plugin { let startTime: Dayjs; let endTime: Dayjs; let outDir: string; + const { green, blue, bold } = picocolors; return { name: "vite:buildInfo", configResolved(resolvedConfig) { @@ -33,7 +34,7 @@ export function viteBuildInfo(): Plugin { closeBundle() { if (config.command === "build") { endTime = dayjs(new Date()); - utils.getPackageSize({ + getPackageSize({ folder: outDir, callback: (size: string) => { console.log( diff --git a/build/plugins.ts b/build/plugins.ts index 731e802a15..89bc49e25f 100644 --- a/build/plugins.ts +++ b/build/plugins.ts @@ -8,7 +8,7 @@ import { viteMockServe } from "vite-plugin-mock"; import { configCompressPlugin } from "./compress"; import { visualizer } from "rollup-plugin-visualizer"; import removeConsole from "vite-plugin-remove-console"; -import themePreprocessorPlugin from "@pureadmin/theme"; +import { themePreprocessorPlugin } from "@pureadmin/theme"; import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"; import { genScssMultipleScopeVars } from "../src/layout/theme"; diff --git a/build/utils.ts b/build/utils.ts new file mode 100644 index 0000000000..2f11e0f158 --- /dev/null +++ b/build/utils.ts @@ -0,0 +1,34 @@ +import { readdir, stat } from "node:fs"; +import { sum, formatBytes } from "@pureadmin/utils"; + +const fileListTotal: number[] = []; + +/** + * @description 获取指定文件夹中所有文件的总大小 + */ +export const getPackageSize = options => { + const { folder = "dist", callback, format = true } = options; + readdir(folder, (err, files: string[]) => { + if (err) throw err; + let count = 0; + const checkEnd = () => { + ++count == files.length && + callback(format ? formatBytes(sum(fileListTotal)) : sum(fileListTotal)); + }; + 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()) { + getPackageSize({ + folder: `${folder}/${item}/`, + callback: checkEnd + }); + } + }); + }); + files.length === 0 && callback(0); + }); +}; diff --git a/package.json b/package.json index 22c18ed8ef..d6cb0a7b94 100644 --- a/package.json +++ b/package.json @@ -109,8 +109,8 @@ "@iconify-icons/ri": "^1.2.10", "@iconify/vue": "^4.1.1", "@intlify/unplugin-vue-i18n": "^1.4.0", - "@pureadmin/theme": "^3.1.0", "@types/intro.js": "^5.1.3", + "@pureadmin/theme": "^3.2.0", "@types/js-cookie": "^3.0.4", "@types/mockjs": "^1.0.8", "@types/node": "^20.8.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 734588caf9..21791e81f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -191,8 +191,8 @@ devDependencies: specifier: ^1.4.0 version: 1.4.0(vue-i18n@9.5.0) '@pureadmin/theme': - specifier: ^3.1.0 - version: 3.1.0 + specifier: ^3.2.0 + version: 3.2.0 '@types/intro.js': specifier: ^5.1.3 version: 5.1.3 @@ -1774,8 +1774,8 @@ packages: vue: 3.3.4 dev: false - /@pureadmin/theme@3.1.0: - resolution: {integrity: sha512-3kBbqB6Uua096w91w1SrGna0dM8AYO5HFk/HU8G0DsEaijgRrm+dYIJUrqbv+stLUxlYPNVXpDS/APZjF0cOAg==} + /@pureadmin/theme@3.2.0: + resolution: {integrity: sha512-SBlTvEl0rmfqTW/mOJUPftvZe4yF+38CJdlBOvVITpehzCytqlG5i8XKpcs8aAR9SVfhcrLVS5Q6xh7xDVQcJQ==} dependencies: '@zougt/some-loader-utils': 1.4.3 fs-extra: 11.1.1 diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts index 5e26adfab1..a8a07cc6bf 100644 --- a/src/utils/http/index.ts +++ b/src/utils/http/index.ts @@ -73,7 +73,7 @@ class PureHttp { return config; } /** 请求白名单,放置一些不需要token的接口(通过设置请求白名单,防止token过期后再请求造成的死循环问题) */ - const whiteList = ["/refreshToken", "/login"]; + const whiteList = ["/refresh-token", "/login"]; return whiteList.find(url => url === config.url) ? config : new Promise(resolve => {