.env
一个 .env 文件用于指定构建和开发环境变量
使用
创建.env 文件
- .env.development 本地环境
bash
// .env.development 本地环境
NUXT_NODE_ENV = development
NUXT_BASE_URL = http://yfnimg.bestsmell.cn:10011
- .env.production 生产环境
bash
NUXT_NODE_ENV = production
NUXT_BASE_URL = https://api.yfn.com
- .env.test 测试环境
bash
NUXT_NODE_ENV = pre
NUXT_BASE_URL = https://pre-api.yfn.com
配置运行,编译环境 package.json
bash
// --dotenv 指定 env 文件
"dev": "nuxt dev --dotenv .env.development --exec",
"pre": "nuxt dev --dotenv .env.test --exec",
"pro": "nuxt dev --dotenv .env.production --exec",
"build": "nuxt build --dotenv .env.development --exec",
"build:pre": "nuxt build --dotenv .env.test --exec",
"build:pro": "nuxt build --dotenv .env.production --exec",
nuxt.config.ts 内配置
本地运行
bash
// 运行测试环境
npm run dev
or
yarn dev
// 运行预发环境
npm run pre
or
yarn pre
// 运行生产环境
npm run pro
or
yarn pro