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.
This commit is contained in:
wizardchen
2026-02-28 16:23:38 +08:00
committed by lyingbug
parent 2a5cf57589
commit 31755726a0
+19 -1
View File
@@ -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: {