-
-
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
Comments
You described the situation well 🙂 The default use of As you mentioned, it is common to have a few types of server environments for an application. These should all run the optimized Create-react-app mandates that you prefix any custom environment variables with
You can access the variable in your app with
I haven't personally tried this with create-react-app, but check out the cross-env package. It allows setting environment variables in a cross-platform manner. You could then simplify your
Then run |
The easiest way to achieve this is via Instead, create one for each environment.
Then you can just add some extra scripts in your {
"scripts": {
"build:staging": "env-cmd .env.staging yarn build",
"build:qa": "env-cmd .env.qa yarn build"
}
} In this scenario, |
env-cmd
Hi i'd like to do this. But as a quick note, basically what I am going to do is edit the docs to state what you guys just stated in a higher level way? Should I simply do so, with say, a few sentences and a short code snippet or ought I be more detailed? |
I'd say add a section under "Building for Relative Paths" in "Deployment" named "Building for Multiple Environments" and then give a more doc-y explanation of the solution I gave above. |
Great, going to start working on it today |
@Timer Good guy , That is good idea , tks. |
* 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
Documentation added in #4117. |
* 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 ...
…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
The term "development environment", "test environment" and "production environment" is used differently across the contexts and sometimes cause confusion for users.
create-react-app defines the environment name by the state of app code build: "development" means the code is not minified and run in live reload mode on local machines, "test" means the code is executing in unit test process, "production" means the code is minified and optimized with source map. I'll call this "development build", "test build" and "production build".
Mean while, in large portion of the software industry, these terms are used differently:
In the diagram above, I'll call them deploy environment, each deploy environment is a set of all the services that linked and worked with each other in an isolated place (servers/VPN).
"Frontend" is where create-react-app lives, and this all run "production build" of the app, which means the code is minified and optimized.
The problem
Regarding this document: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables
NODE_ENV
always resolves toproduction
when built withyarn build
, even if we try to runNODE_ENV=staging yarn build
.What I have been doing to resolve this
yarn build-staging
,yarn build-production
,... In the script, it creates.env
file according the deployment environment and build. Ex:mv env/staging.env ./.env && yarn build
.https://staging-my-app.com/env
)Better way?
What is the best practice here? Have anyone of you run into this problem? How did you do it? Should
create-react-app
do something about this? Please share, thanks!The text was updated successfully, but these errors were encountered: