From a8e264f65202f82fb512733f4e71a12f0d66f37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cls=5F=E5=AE=81=E6=B3=A2=E6=9C=AC=E6=9C=BA?= <908705107@qq.com> Date: Tue, 9 Jun 2026 08:15:26 +0800 Subject: [PATCH] Fix web production build pipeline --- web/.node-version | 2 +- web/apps/web-ele/.env.production | 1 + web/apps/web-ele/trace-build-imports.mjs | 46 ------ web/apps/web-ele/vite.config.mts | 137 ++++++++++++++++-- web/internal/node-utils/build.config.ts | 3 + web/internal/vite-config/build.config.ts | 3 + web/internal/vite-config/src/plugins/index.ts | 9 +- web/package.json | 2 +- .../effects/common-ui/src/ui/index.ts | 1 - web/trace-build-imports.mjs | 49 ------- 10 files changed, 143 insertions(+), 110 deletions(-) delete mode 100644 web/apps/web-ele/trace-build-imports.mjs delete mode 100644 web/trace-build-imports.mjs diff --git a/web/.node-version b/web/.node-version index ee5c244..5b54067 100644 --- a/web/.node-version +++ b/web/.node-version @@ -1 +1 @@ -22.1.0 +22.16.0 diff --git a/web/apps/web-ele/.env.production b/web/apps/web-ele/.env.production index 3bf7ed3..40a2fa7 100644 --- a/web/apps/web-ele/.env.production +++ b/web/apps/web-ele/.env.production @@ -1,3 +1,4 @@ +VITE_APP_TITLE=AI Agent Admin VITE_BASE=/ai-agent-admin/ VITE_GLOB_API_URL=/ai-agent-admin/basic-api VITE_COMPRESS=none diff --git a/web/apps/web-ele/trace-build-imports.mjs b/web/apps/web-ele/trace-build-imports.mjs deleted file mode 100644 index ffe8707..0000000 --- a/web/apps/web-ele/trace-build-imports.mjs +++ /dev/null @@ -1,46 +0,0 @@ -import { build } from 'vite'; - -function tracePlugin() { - const importers = []; - return { - name: 'trace-jiti-importer', - async resolveId(source, importer, options) { - if (source.includes('jiti') || importer?.includes('jiti')) { - console.log('[resolve]', JSON.stringify({ source, importer })); - } - const resolved = await this.resolve(source, importer, { - ...options, - skipSelf: true, - }); - if (resolved?.id?.includes('jiti') || source.includes('jiti')) { - console.log( - '[resolved]', - JSON.stringify({ source, importer, resolved: resolved?.id }), - ); - } - return resolved; - }, - moduleParsed(info) { - if (info.importedIds.some((id) => id.includes('jiti'))) { - importers.push({ - id: info.id, - importedIds: info.importedIds.filter((id) => id.includes('jiti')), - }); - console.log('[imports-jiti]', JSON.stringify(importers.at(-1))); - } - if (info.id.includes('jiti')) { - console.log('[module-jiti]', info.id); - console.log('[jiti-importers]', JSON.stringify(importers, null, 2)); - } - }, - }; -} - -await build({ - configFile: './vite.config.mts', - mode: 'production', - plugins: [tracePlugin()], - build: { - write: false, - }, -}); diff --git a/web/apps/web-ele/vite.config.mts b/web/apps/web-ele/vite.config.mts index 25224b2..b011ff6 100644 --- a/web/apps/web-ele/vite.config.mts +++ b/web/apps/web-ele/vite.config.mts @@ -7,6 +7,11 @@ import ElementPlus from 'unplugin-element-plus/vite'; const resolveLocal = (path: string) => fileURLToPath(new URL(path, import.meta.url)); +const exactAlias = (find: string, path: string) => ({ + find: new RegExp(`^${find.replaceAll('/', '\\/')}$`), + replacement: resolveLocal(path), +}); + export default defineConfig(async () => { return { application: { @@ -15,32 +20,142 @@ export default defineConfig(async () => { }, vite: { resolve: { - alias: { - '#/components/form-editor': resolveLocal( + alias: [ + exactAlias( + '#/components/form-editor', './src/components/ai-chat-panel/form-editor-lite.ts', ), - '@vben-core/shared/cache': resolveLocal( + exactAlias( + '@vben-core/design', + '../../packages/@core/base/design/src/index.ts', + ), + exactAlias( + '@vben-core/design/bem', + '../../packages/@core/base/design/src/scss-bem/bem.scss', + ), + exactAlias( + '@vben-core/composables', + '../../packages/@core/composables/src/index.ts', + ), + exactAlias( + '@vben-core/form-ui', + '../../packages/@core/ui-kit/form-ui/src/index.ts', + ), + exactAlias( + '@vben-core/icons', + '../../packages/@core/base/icons/src/index.ts', + ), + exactAlias( + '@vben-core/layout-ui', + '../../packages/@core/ui-kit/layout-ui/src/index.ts', + ), + exactAlias( + '@vben-core/menu-ui', + '../../packages/@core/ui-kit/menu-ui/src/index.ts', + ), + exactAlias( + '@vben-core/popup-ui', + '../../packages/@core/ui-kit/popup-ui/src/index.ts', + ), + exactAlias( + '@vben-core/preferences', + '../../packages/@core/preferences/src/index.ts', + ), + exactAlias( + '@vben-core/shadcn-ui', + '../../packages/@core/ui-kit/shadcn-ui/src/index.ts', + ), + exactAlias( + '@vben-core/shared/cache', '../../packages/@core/base/shared/src/cache/index.ts', ), - '@vben-core/shared/color': resolveLocal( + exactAlias( + '@vben-core/shared/color', '../../packages/@core/base/shared/src/color/index.ts', ), - '@vben-core/shared/constants': resolveLocal( + exactAlias( + '@vben-core/shared/constants', '../../packages/@core/base/shared/src/constants/index.ts', ), - '@vben-core/shared/global-state': resolveLocal( + exactAlias( + '@vben-core/shared/global-state', '../../packages/@core/base/shared/src/global-state.ts', ), - '@vben-core/shared/store': resolveLocal( + exactAlias( + '@vben-core/shared/store', '../../packages/@core/base/shared/src/store.ts', ), - '@vben-core/shared/utils': resolveLocal( + exactAlias( + '@vben-core/shared/utils', '../../packages/@core/base/shared/src/utils/index.ts', ), - 'pinia-plugin-persistedstate': resolveLocal( - '../../node_modules/pinia-plugin-persistedstate/dist/index.js', + exactAlias( + '@vben-core/tabs-ui', + '../../packages/@core/ui-kit/tabs-ui/src/index.ts', ), - }, + exactAlias( + '@vben-core/typings', + '../../packages/@core/base/typings/src/index.ts', + ), + exactAlias( + '@vben/access', + '../../packages/effects/access/src/index.ts', + ), + exactAlias( + '@vben/common-ui', + '../../packages/effects/common-ui/src/index.ts', + ), + exactAlias( + '@vben/common-ui/es/tippy', + '../../packages/effects/common-ui/src/components/tippy/index.ts', + ), + exactAlias( + '@vben/constants', + '../../packages/constants/src/index.ts', + ), + exactAlias( + '@vben/hooks', + '../../packages/effects/hooks/src/index.ts', + ), + exactAlias('@vben/icons', '../../packages/icons/src/index.ts'), + exactAlias( + '@vben/layouts', + '../../packages/effects/layouts/src/index.ts', + ), + exactAlias( + '@vben/layouts/preferences-blocks', + '../../packages/effects/layouts/src/widgets/preferences/blocks/index.ts', + ), + exactAlias('@vben/locales', '../../packages/locales/src/index.ts'), + exactAlias( + '@vben/plugins/echarts', + '../../packages/effects/plugins/src/echarts/index.ts', + ), + exactAlias( + '@vben/plugins/motion', + '../../packages/effects/plugins/src/motion/index.ts', + ), + exactAlias( + '@vben/plugins/vxe-table', + '../../packages/effects/plugins/src/vxe-table/index.ts', + ), + exactAlias( + '@vben/preferences', + '../../packages/preferences/src/index.ts', + ), + exactAlias( + '@vben/request', + '../../packages/effects/request/src/index.ts', + ), + exactAlias('@vben/stores', '../../packages/stores/src/index.ts'), + exactAlias('@vben/styles', '../../packages/styles/src/index.ts'), + exactAlias( + '@vben/styles/ele', + '../../packages/styles/src/ele/index.css', + ), + exactAlias('@vben/types', '../../packages/types/src/index.ts'), + exactAlias('@vben/utils', '../../packages/utils/src/index.ts'), + ], }, plugins: [ ElementPlus({ diff --git a/web/internal/node-utils/build.config.ts b/web/internal/node-utils/build.config.ts index 97e572c..ff4e0f7 100644 --- a/web/internal/node-utils/build.config.ts +++ b/web/internal/node-utils/build.config.ts @@ -4,4 +4,7 @@ export default defineBuildConfig({ clean: true, declaration: true, entries: ['src/index'], + stubOptions: { + absoluteJitiPath: true, + }, }); diff --git a/web/internal/vite-config/build.config.ts b/web/internal/vite-config/build.config.ts index 97e572c..ff4e0f7 100644 --- a/web/internal/vite-config/build.config.ts +++ b/web/internal/vite-config/build.config.ts @@ -4,4 +4,7 @@ export default defineBuildConfig({ clean: true, declaration: true, entries: ['src/index'], + stubOptions: { + absoluteJitiPath: true, + }, }); diff --git a/web/internal/vite-config/src/plugins/index.ts b/web/internal/vite-config/src/plugins/index.ts index 8faa6c9..acabb06 100644 --- a/web/internal/vite-config/src/plugins/index.ts +++ b/web/internal/vite-config/src/plugins/index.ts @@ -193,7 +193,14 @@ async function loadApplicationPlugins( }, { condition: !!html, - plugins: () => [viteHtmlPlugin({ minify: true })], + plugins: () => [ + viteHtmlPlugin({ + inject: { + data: env, + }, + minify: true, + }), + ], }, { condition: isBuild && importmap, diff --git a/web/package.json b/web/package.json index 46ea9dd..16c6bc6 100644 --- a/web/package.json +++ b/web/package.json @@ -101,7 +101,7 @@ "vue-tsc": "catalog:" }, "engines": { - "node": ">=20.10.0", + "node": ">=20.19.0 || >=22.12.0", "pnpm": ">=9.12.0" }, "packageManager": "pnpm@10.14.0", diff --git a/web/packages/effects/common-ui/src/ui/index.ts b/web/packages/effects/common-ui/src/ui/index.ts index fb99fde..44ba0e8 100644 --- a/web/packages/effects/common-ui/src/ui/index.ts +++ b/web/packages/effects/common-ui/src/ui/index.ts @@ -1,4 +1,3 @@ export * from './about'; export * from './authentication'; -export * from './dashboard'; export * from './fallback'; diff --git a/web/trace-build-imports.mjs b/web/trace-build-imports.mjs deleted file mode 100644 index 4463e46..0000000 --- a/web/trace-build-imports.mjs +++ /dev/null @@ -1,49 +0,0 @@ -import { build } from 'vite'; - -const seen = new Map(); - -function tracePlugin() { - return { - name: 'trace-jiti-importer', - async resolveId(source, importer, options) { - if (source.includes('jiti') || importer?.includes('jiti')) { - console.log('[resolve]', { source, importer }); - } - const resolved = await this.resolve(source, importer, { - ...options, - skipSelf: true, - }); - if (resolved?.id?.includes('jiti') || source.includes('jiti')) { - console.log('[resolved]', { source, importer, resolved: resolved?.id }); - } - return resolved; - }, - load(id) { - if (id.includes('jiti')) { - console.log('[load]', id); - } - return null; - }, - moduleParsed(info) { - if (info.id.includes('jiti')) { - console.log('[moduleParsed]', info.id); - console.log( - '[importers]', - Array.from(seen.entries()).filter(([, imports]) => - imports.some((item) => item.includes('jiti')), - ), - ); - } - seen.set(info.id, Array.from(info.importedIds)); - }, - }; -} - -await build({ - configFile: './apps/web-ele/vite.config.mts', - mode: 'production', - plugins: [tracePlugin()], - build: { - write: false, - }, -});