react
使用REACT_APP_ENV 的方式
"build:staging": "rimraf build && REACT_APP_ENV=staging PUBLIC_URL=./ node scripts/build.js",
代码中使用REACT_APP_ENV
process.env.REACT_APP_ENV === 'staging' ? 'a' : 'b'
vue3 基于vite
"build:staging": "vite build --mode staging",
创建 文件 .env.staging
# .env.staging
VITE_APP_URL=https://test-xxxxx.com
创建文件 .env.production
# .env.production
VITE_APP_URL=https://xxxxx.com
代码中使用
直接使用 import.meta.env.VITE_APP_URL