Skip to content

Commit bbe33cd

Browse files
committed
feat: 添加环境变量.env
添加.env配置,区分开发和生产配置
1 parent 2f51c1f commit bbe33cd

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

.env.development

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 只在开发模式中被载入
2+
3+
# 网站前缀
4+
VITE_BASE_URL = /
5+
6+
# API - 本地通过/api代理
7+
VITE_API_URL = '/api'

.env.production

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 只在生产模式中被载入
2+
3+
# 网站前缀
4+
VITE_BASE_URL = https://cloud-app.com.cn/
5+
6+
# API
7+
VITE_API_URL = 'https://cloud-app.com.cn/'

env.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
/// <reference types="vite/client" />
2+
interface ImportMetaEnv {
3+
readonly BASE_URL: string
4+
readonly MODE: string
5+
readonly VITE_BASE_URL: string
6+
readonly VITE_API_URL: string
7+
}
8+
9+
interface ImportMeta {
10+
readonly env: ImportMetaEnv
11+
}

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ app.use(createPinia())
1212
app.use(router)
1313

1414
console.log(import.meta.env)
15+
console.log(import.meta.env.VITE_BASE_URL)
16+
1517
// @ts-ignore
1618
console.log(process.env)
1719

0 commit comments

Comments
 (0)