From 31755726a0f75b54e3588e6b35b23e1be13c79b6 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Sat, 28 Feb 2026 16:23:38 +0800 Subject: [PATCH] feat: enhance Vite configuration for dynamic module resolution - Introduced a new function to dynamically resolve the '@vue-office/pptx' module path, improving compatibility with different package structures. - Replaced the static module resolution with the new function in the Vite configuration, ensuring more robust handling of the module during the build process. This update enhances the flexibility of module resolution in the Vite setup. --- frontend/vite.config.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 7ed2c645..42d64dbe 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,11 +1,29 @@ import { fileURLToPath, URL } from 'node:url' +import { resolve, dirname } from 'node:path' +import { existsSync } from 'node:fs' import { createRequire } from 'node:module' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' +const __dirname = dirname(fileURLToPath(import.meta.url)) const require = createRequire(import.meta.url) +function resolveVueOfficePptxEntry(): string { + try { + const pkgDir = dirname(require.resolve('@vue-office/pptx/package.json')) + const candidates = [ + resolve(pkgDir, 'lib/v3/index.js'), + resolve(pkgDir, 'lib/index.js'), + resolve(pkgDir, 'lib/v3/vue-office-pptx.mjs'), + ] + const matched = candidates.find((candidate) => existsSync(candidate)) + return matched ?? '@vue-office/pptx' + } catch { + return '@vue-office/pptx' + } +} + export default defineConfig({ plugins: [ vue(), @@ -14,7 +32,7 @@ export default defineConfig({ resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), - '@vue-office/pptx': require.resolve('@vue-office/pptx/lib/index.js'), + '@vue-office/pptx': resolveVueOfficePptxEntry(), }, }, server: {