其实查看 create-react-app 的官方文档可以发现,create-react-app 默认是支持多个环境配置文件的:
.env:默认。.env.local:本地覆盖。除 test 之外的所有环境都加载此文件。.env.development,.env.test,.env.production:设置特定环境。.env.development.local,.env.test.local,.env.production.local:设置特定环境的本地覆盖。
左侧的文件比右侧的文件具有更高的优先级:
npm start:.env.development.local,.env.development,.env.local,.envnpm run build:.env.production.local,.env.production,.env.local,.envnpm test:.env.test.local,.env.test,.env(注意没有.env.local)