Skip to content
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

Merged
merged 6 commits into from
Apr 15, 2018
Merged

Document multiple build environments via env-cmd #4071 #4117

merged 6 commits into from
Apr 15, 2018

Conversation

jmuzsik
Copy link

@jmuzsik jmuzsik commented Mar 6, 2018

#4071

Hi, in reference to issue 4071

A doc issue:

screen shot 2018-03-06 at 18 09 44

screen shot 2018-03-06 at 18 09 52

screen shot 2018-03-06 at 18 09 58

And that's exactly what it looks like around the surrounding context!

@facebook-github-bot
Copy link

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 [email protected]. Thanks!

@facebook-github-bot
Copy link

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`
Copy link
Contributor

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:
Copy link
Contributor

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.

@jmuzsik
Copy link
Author

jmuzsik commented Mar 8, 2018

Ok, new format:

screen shot 2018-03-08 at 16 10 43

screen shot 2018-03-08 at 16 10 50

What do you think? @iansu

@Timer Timer added this to the 2.x milestone Mar 26, 2018
@@ -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.
Copy link
Contributor

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:
Copy link
Contributor

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`
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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"

@jmuzsik
Copy link
Author

jmuzsik commented Apr 14, 2018

Thanks @iansu! Hope it looks good now

@Timer
Copy link
Contributor

Timer commented Apr 15, 2018

This looks great -- I made a couple final tweaks.

Thanks much!

@Timer Timer merged commit fc2f63a into facebook:next Apr 15, 2018
@Timer Timer modified the milestones: 2.x, 100.0.0, 2.0.0 Apr 15, 2018
kellyrmilligan added a commit to kellyrmilligan/create-react-app that referenced this pull request May 2, 2018
* 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
  ...
kellyrmilligan added a commit to kellyrmilligan/create-react-app that referenced this pull request May 2, 2018
* 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
  ...
@niwsa
Copy link

niwsa commented May 19, 2018

@Timer The readme does not have a updated documentation for multiple environments.

@Timer
Copy link
Contributor

Timer commented May 19, 2018

It's on the next branch. :)

@gmonte
Copy link

gmonte commented Jun 1, 2018

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.
How would I do if I wanted to run babel plugins on a specific env?

@Timer
Copy link
Contributor

Timer commented Jun 1, 2018

You cannot change NODE_ENV or BABEL_ENV.

zmitry pushed a commit to zmitry/create-react-app that referenced this pull request Sep 30, 2018
…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
@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants