- 新增.env.development/.env.production环境配置 - vite.config.ts支持VITE_BASE动态base路径 - router使用import.meta.env.BASE_URL - API baseURL使用环境变量 - 新增vite-env.d.ts类型声明
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { VantResolver } from '@vant/auto-import-resolver'
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
// 加载环境变量
|
|
const env = loadEnv(mode, process.cwd())
|
|
const base = env.VITE_BASE || '/'
|
|
|
|
return {
|
|
// 部署路径前缀
|
|
base,
|
|
plugins: [
|
|
vue(),
|
|
Components({
|
|
resolvers: [VantResolver()]
|
|
})
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
}
|
|
},
|
|
server: {
|
|
port: 8080,
|
|
proxy: {
|
|
'/sys': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
},
|
|
'/cust': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
},
|
|
'/proj': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
},
|
|
'/exp': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
},
|
|
'/receipt': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
},
|
|
'/file': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|