-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document multiple build environments via env-cmd
#4071
#4117
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
||
- But you can run: | ||
|
||
- `REACT_APP_NODE_ENV=staging npm run build` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using NODE_ENV
and REACT_APP_NODE_ENV
for this example is potentially confusing. The similar names implies that there is some connection between them. The example we commonly use is something like REACT_APP_API_URL
which is set to one value in .env.production
or .env
and then overridden for other environments.
|
||
But, the ideal way is to use `.env` files as you can specify many environment variables simultaneously. This can be done as so: | ||
|
||
Within `.env.staging` write this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These instructions should mention the env-cmd
package and how to install it.
Ok, new format: What do you think? @iansu |
@@ -2196,6 +2196,46 @@ If you are not using the HTML5 `pushState` history API or not using client-side | |||
|
|||
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. | |||
|
|||
#### Building for Multiple Environments | |||
|
|||
Applications are generally split between different environments such as staging, production, and development. To allow the app to run in these different environments one must set environment variables to be able to conditionally run different processes depending on the specified environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove lines 2201 through 2209. It's explained elsewhere how Create React App handles environment variables and we don't need to cover it again.
|
||
- So you cannot depend upon using `NODE_ENV` to set the environment of your application. | ||
|
||
The ideal way to do this is to use `.env` files as you can specify many environment variables simultaneously. This can be done as so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to something like: "You can specify a new environment by creating a custom env file. For example, to specify config for a staging environment create a file named .env.staging
."
|
||
- To install `env-cmd` you can do so either locally or globally: | ||
|
||
- `npm install env-cmd` or `npm install -g env-cmd` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave out the option of globally install env-cmd
.
// ... | ||
} | ||
``` | ||
Then you can run `npm run build:staging` or whatever other environment you would like to set up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to something like "Then you can run npm run build:staging
to build with the staging environment config. You can specify other environments in the same way."
@@ -2196,6 +2196,46 @@ If you are not using the HTML5 `pushState` history API or not using client-side | |||
|
|||
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. | |||
|
|||
#### Building for Multiple Environments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to something like "Customizing Environment Variables for a Build"
Thanks @iansu! Hope it looks good now |
This looks great -- I made a couple final tweaks. Thanks much! |
* upstream/next: (35 commits) Update envinfo and issue template (facebook#4375) Update sass-loader to 7.0.1 (facebook#4376) Support package distribution tags (facebook#4350) fix broken css module support in prod (facebook#4361) Bumped jest version to 22.4.1 (facebook#4362) bump babel 7 to beta 46 bump lint-staged to node 10 compatible version documentation: Added License to the README.md (facebook#4294) Bump `fsevents`. (facebook#4331) Fix typo in e2e-simple.sh comment (facebook#4323) Add Sass loader (facebook#4195) Fix some typos in README.md (facebook#4286) Added learnstorybook.com to Storybook links (facebook#4298) Document multiple build environments via `env-cmd` facebook#4071 (facebook#4117) Fixed link to CSS imports blog post Update CSS Modules localIndetName (facebook#4192) Enable loose mode for `class-properties` (facebook#4248) bump babel 7 beta (facebook#4253) Small typo fix facebook#4217 Changelog for 1.1.4 ...
* next: (35 commits) Update envinfo and issue template (facebook#4375) Update sass-loader to 7.0.1 (facebook#4376) Support package distribution tags (facebook#4350) fix broken css module support in prod (facebook#4361) Bumped jest version to 22.4.1 (facebook#4362) bump babel 7 to beta 46 bump lint-staged to node 10 compatible version documentation: Added License to the README.md (facebook#4294) Bump `fsevents`. (facebook#4331) Fix typo in e2e-simple.sh comment (facebook#4323) Add Sass loader (facebook#4195) Fix some typos in README.md (facebook#4286) Added learnstorybook.com to Storybook links (facebook#4298) Document multiple build environments via `env-cmd` facebook#4071 (facebook#4117) Fixed link to CSS imports blog post Update CSS Modules localIndetName (facebook#4192) Enable loose mode for `class-properties` (facebook#4248) bump babel 7 beta (facebook#4253) Small typo fix facebook#4217 Changelog for 1.1.4 ...
It's on the next branch. :) |
Ok... But my .babelrc always get env production. {
"env": {
"production": {
"plugins": [
"transform-remove-console"
]
}
},
"presets": [
"react-app"
]
} In that case I will never have consoles in my build, even if I run build with another .env. |
You cannot change |
…ebook#4117) * Docs - Document multiple build environments via * Docs - Document multiple build environments via * Docs - Document multiple build environments via * Docs - Document multiple build environments via env-cmd * fix - based upon requests * Update README.md
#4071
Hi, in reference to issue 4071
A doc issue:
And that's exactly what it looks like around the surrounding context!