Files
Enterprise-Knowledge-Base/frontend/vite.config.ts
T
wizardchen 31755726a0 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.
2026-03-02 21:21:49 +08:00

56 lines
1.4 KiB
TypeScript

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(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@vue-office/pptx': resolveVueOfficePptxEntry(),
},
},
server: {
port: 5173,
host: true,
// 代理配置,用于开发环境
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
},
'/files': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
}
}
}
})