mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-07 06:12:44 +08:00
在 vite.config.ts 中添加 ESM 兼容的 __dirname 定义,修复 Docker 构建时的配置加载错误 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd() + '/../')
|
|
|
|
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://127.0.0.1:8483'
|
|
const port = parseInt(env.VITE_FRONTEND_PORT || '3015', 10)
|
|
|
|
return {
|
|
base: './',
|
|
plugins: [react(), tailwindcss()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
markdown: ['react-markdown', 'react-syntax-highlighter', 'remark-gfm', 'remark-math', 'rehype-katex'],
|
|
markmap: ['markmap-lib', 'markmap-view', 'markmap-toolbar', 'markmap-common'],
|
|
vendor: ['react', 'react-dom', 'react-router-dom'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: port,
|
|
allowedHosts: true, // 允许任意域名访问
|
|
proxy: {
|
|
'/api': {
|
|
target: apiBaseUrl,
|
|
changeOrigin: true,
|
|
rewrite: path => path.replace(/^\/api/, '/api'),
|
|
},
|
|
'/static': {
|
|
target: apiBaseUrl,
|
|
changeOrigin: true,
|
|
rewrite: path => path.replace(/^\/static/, '/static'),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
})
|