You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Building for Relative Paths](#building-for-relative-paths)
90
+
-[Customizing Environment Variables for Arbitrary Build Environments](#customizing-environment-variables-for-arbitrary-build-environments)
90
91
-[Azure](#azure)
91
92
-[Firebase](#firebase)
92
93
-[GitHub Pages](#github-pages)
@@ -2211,6 +2212,34 @@ If you are not using the HTML5 `pushState` history API or not using client-side
2211
2212
2212
2213
This will make sure that all the asset paths are relative to `index.html`. You will then be able to move your app from `http://mywebsite.com` to `http://mywebsite.com/relativepath` or even `http://mywebsite.com/relative/path` without having to rebuild it.
2213
2214
2215
+
### Customizing Environment Variables for Arbitrary Build Environments
2216
+
2217
+
You can create an arbitrary build environment by creating a custom `.env` file and loading it using [env-cmd](https://www.npmjs.com/package/env-cmd).
2218
+
2219
+
For example, to create a build environment for a staging environment:
2220
+
2221
+
1. Create a file called `.env.staging`
2222
+
1.Set environment variables as you would any other `.env`file (e.g. `REACT_APP_API_URL=http://api-staging.example.com`)
1. Add a newscript to your `package.json`, building with your newenvironment:
2230
+
```json
2231
+
{
2232
+
"scripts": {
2233
+
"build:staging": "env-cmd .env.staging npm run build",
2234
+
}
2235
+
}
2236
+
```
2237
+
2238
+
Now you can run `npm run build:staging` to build with the staging environment config.
2239
+
You can specify other environments in the same way.
2240
+
2241
+
Variables in`.env.production` will be used as fallback because `NODE_ENV` will always be set to `production`for a build.
2242
+
2214
2243
### [Azure](https://azure.microsoft.com/)
2215
2244
2216
2245
See [this](https://medium.com/@to_pe/deploying-create-react-app-on-microsoft-azure-c0f6686a4321) blog post on how to deploy your React app to Microsoft Azure.
0 commit comments