feat: 更新 Vite 配置以支持环境变量和基础路径

This commit is contained in:
zhongyidian committed 2025-09-14 13:15:21 +08:00
1 parent 30f2d5e1f6
commit 66842e9d58
3 files changed
+23 -2

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
# 环境
VITE_NODE_ENV=development
# 线上环境平台打包路径
VITE_BASE_PATH=/super-video-h5
+6
View File
@@ -0,0 +1,6 @@
# 环境
VITE_NODE_ENV=production
# 线上环境平台打包路径
VITE_BASE_PATH=/super-video-h5
+9 -2
View File
@@ -1,13 +1,20 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// 当前工作目录路径
const root: string = process.cwd()
// https://vite.dev/config/
export default defineConfig({
export default defineConfig(({ mode }) => {
// 环境变量
const env = loadEnv(mode, root, '')
return {
plugins: [vue()],
base: env.VITE_BASE_PATH || '/',
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
}
}
})