Skip to content

Commit

Permalink
chore: 修改环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
huangmingfu committed Nov 2, 2024
1 parent 75d72ca commit 93b94bd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default { extends: ['@commitlint/config-conventional'] }; // 继承 @comm
* feat:新功能(feature)
* fix:修复 bug
* docs:文档更改
* style:代码格式(不影响代码运行的变动,如空格、分号等)
* style:样式
* refactor:重构(既不是新功能也不是修复 bug 的代码改动)
* perf:性能优化
* perf:优化
* test:增加测试
* chore:构建过程或辅助工具的变动
* ci:持续集成相关配置的更改
Expand Down
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
# VITE_ 前缀的变量会被 Vite 自动注入到客户端代码中,可以通过 import.meta.env.VITE_MY_APP_PREFIX 访问。
# 这些变量在开发环境、生产环境和测试环境中都会生效。

## 项目标题
# 项目标题
VITE_APP_TITLE = React-Ts-Template

# 端口号
VITE_APP_PORT = 5173
5 changes: 1 addition & 4 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# js中通过`import.meta.env.VITE_APP_BASE_API`取值

# 环境
VITE_NODE_ENV = develop

#端口号
VITE_APP_PORT = 5173
VITE_NODE_ENV = development

# 接口前缀
VITE_APP_BASE_API = '/dev-api'
Expand Down
3 changes: 0 additions & 3 deletions .env.pro
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# 环境
VITE_NODE_ENV = production

# 端口号
VITE_APP_PORT = 5173

# 接口前缀
VITE_APP_BASE_API = '/pro-api'

Expand Down
3 changes: 0 additions & 3 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# 环境
VITE_NODE_ENV = test

#端口号
VITE_APP_PORT = 5173

# 接口前缀
VITE_APP_BASE_API = '/test-api'

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --mode dev",
"dev:test": "vite --mode test",
"dev:pro": "vite --mode pro",
"build:dev": "tsc -b && pnpm vite build --mode dev",
"build:test": "tsc -b && pnpm vite build --mode test",
"build:pro": "tsc -b && pnpm vite build --mode pro",
Expand Down Expand Up @@ -67,4 +69,4 @@
"node": ">=18.12.0",
"pnpm": ">=9"
}
}
}
5 changes: 3 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
// 获取`.env`环境配置文件
const env = loadEnv(mode, process.cwd());
return {
base: env.VITE_NODE_ENV === 'develop' ? './' : undefined, // 只为github pages配置,可根据情况自行删除
base: env.VITE_NODE_ENV === 'development' ? './' : undefined, // 只为github pages配置,可根据情况自行删除
plugins: [react()],
resolve: {
alias: {
Expand Down Expand Up @@ -38,7 +38,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
}
},
esbuild:
env.VITE_NODE_ENV === 'develop'
env.VITE_NODE_ENV === 'development'
? undefined
: {
/** 打包时移除 console.log */
Expand All @@ -59,6 +59,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
assetFileNames: '[ext]/[name]-[hash].[ext]',
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom']
// 'vendor':['antd']
}
}
}
Expand Down

0 comments on commit 93b94bd

Please sign in to comment.