From 0f2193cc146d517689bb62f23ee6c48fed10fcc2 Mon Sep 17 00:00:00 2001 From: XiaoDaiGua-Ray <443547225@qq.com> Date: Tue, 6 May 2025 09:01:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20vite=20=E6=89=93?= =?UTF-8?q?=E5=8C=85=E6=97=B6=EF=BC=8C=E5=88=86=E5=8C=85=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4=E6=9E=84=E5=BB=BA=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E5=BC=95=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite-helper/chunks-copilot.ts | 18 +++++++++--------- vite.config.ts | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vite-helper/chunks-copilot.ts b/vite-helper/chunks-copilot.ts index 3dd07ba9..a21c04a3 100644 --- a/vite-helper/chunks-copilot.ts +++ b/vite-helper/chunks-copilot.ts @@ -1,5 +1,5 @@ -export const chunksCopilot = (id: string) => { - const utilsLibOptions = 'src/utils' +export const chunksCopilot = () => { + const utilsLibOptions = ['src/utils'] const hooksLibOptions = [ 'src/hooks/components', 'src/hooks/template', @@ -7,15 +7,15 @@ export const chunksCopilot = (id: string) => { ] const nodeModulesOptions = ['node_modules'] - // 是否为模板工程下的 utils 库 - const isUtils = () => id.includes(utilsLibOptions) - // 是否为模板工程下的 hooks 库,不包含 node_modules 库 - const isHooks = () => - hooksLibOptions.some((option) => id.includes(option)) && - !nodeModulesOptions.some((option) => id.includes(option)) // 是否为 node_modules 库 - const isNodeModules = () => + const isNodeModules = (id: string) => nodeModulesOptions.some((option) => id.includes(option)) + // 是否为模板工程下的 utils 库 + const isUtils = (id: string) => + utilsLibOptions.some((option) => id.includes(option) && !isNodeModules(id)) + // 是否为模板工程下的 hooks 库,不包含 node_modules 库 + const isHooks = (id: string) => + hooksLibOptions.some((option) => id.includes(option) && !isNodeModules(id)) return { isUtils, diff --git a/vite.config.ts b/vite.config.ts index 6525748c..bce10b3f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -17,6 +17,7 @@ export default defineConfig(({ mode }) => { appPrimaryColor, base, } = config + const { isUtils, isHooks, isNodeModules } = chunksCopilot() const __APP_CFG__ = { pkg: { @@ -71,18 +72,17 @@ export default defineConfig(({ mode }) => { rollupOptions: { output: { manualChunks: (id) => { - const { isUtils, isHooks, isNodeModules } = chunksCopilot(id) const index = id.includes('pnpm') ? 1 : 0 // 兼容 pnpm, yarn, npm 包管理器差异 - if (isUtils()) { + if (isUtils(id)) { return 'utils' } - if (isHooks()) { + if (isHooks(id)) { return 'hooks' } - if (isNodeModules()) { + if (isNodeModules(id)) { return id .toString() .split('node_modules/')[1]