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

Define process.env as object #807

Merged
merged 4 commits into from
Sep 30, 2016
Merged

Define process.env as object #807

merged 4 commits into from
Sep 30, 2016

Conversation

thien-do
Copy link
Contributor

Issue: #795

@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 - and if you have received this in error or have any questions, please drop us a line 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!

Copy link
Contributor

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a correct fix.

The correct fix would be to use reduce to initialize the env object itself. So you'd use env[key] rather than env['process.env'][key] here, and you’d use NODE_ENV and PUBLIC_URL directly as keys below.

Then you would have the function return { 'process.env': env }. I think this would work.

// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
'process.env.PUBLIC_URL': JSON.stringify(publicUrl)
'process.env': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are overwriting this process.env key in the reduce callback.

@thien-do
Copy link
Contributor Author

Sorry @gaearon , please see my fix.

Also, is that correct to update the NODE_EVN check in webpack.config.prod? https://github.com/facebookincubator/create-react-app/pull/807/files#diff-d2bddbd3bfb7051f9381474c844674faR52

@gaearon gaearon added this to the 0.7.0 milestone Sep 30, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 30, 2016

Yes, this looks right! Thanks.

@gaearon gaearon merged commit 92d9cda into facebook:master Sep 30, 2016
@thien-do thien-do deleted the patch-2 branch September 30, 2016 18:19
kitze added a commit to kitze/custom-react-scripts that referenced this pull request Oct 3, 2016
…react-app

# By Dan Abramov (5) and others
# Via Dan Abramov
* 'master' of https://github.com/facebookincubator/create-react-app:
  docs(readme): peer dependencies applied (facebook#818)
  Fix typos on ISSUE_TEMPLATE.md (facebook#817)
  Add explicit linebreaks (facebook#813)
  Fix typo (facebook#810)
  Fix some typos (facebook#809)
  Beaufity output of eject.js script (facebook#769)
  Define process.env as object (facebook#807)
  Typo fix in webpack.config.dev.js comments (facebook#777)
  Add Netlify to deploy instructions
  Fix usage example to match [email protected] API
  Relaxed eslint rule no-unused-expressions (facebook#724)
  Fix the doc
  Publish
  Add 0.6.1 changelog
  Moved Babel and ESLint config to package.json after ejecting (facebook#773)

Conflicts:
	packages/react-scripts/package.json
@sheerun
Copy link
Contributor

sheerun commented Oct 16, 2016

Such approach can result in large development builds, if process.env.NODE_ENV is used frequently in code.. I't because each time it becomes { whole: "config", NODE_ENV: "dev", ... }.NODE_ENV.

I think the better approach is to create definitions for both, so we get short aliases if possible and at the same time process.env is fully supported.

@gaearon
Copy link
Contributor

gaearon commented Oct 16, 2016

Thanks for spotting. Can you raise an issue about this?

feiqitian pushed a commit to feiqitian/create-react-app that referenced this pull request Oct 25, 2016
* Define process.env as object

* Fix define process.env

* fix NODE_ENV check

* Fix style nitpick
maltestenzel pushed a commit to maltestenzel/custom-react-scripts that referenced this pull request Mar 7, 2018
…react-app

# By Dan Abramov (5) and others
# Via Dan Abramov
* 'master' of https://github.com/facebookincubator/create-react-app:
  docs(readme): peer dependencies applied (facebook#818)
  Fix typos on ISSUE_TEMPLATE.md (facebook#817)
  Add explicit linebreaks (facebook#813)
  Fix typo (facebook#810)
  Fix some typos (facebook#809)
  Beaufity output of eject.js script (facebook#769)
  Define process.env as object (facebook#807)
  Typo fix in webpack.config.dev.js comments (facebook#777)
  Add Netlify to deploy instructions
  Fix usage example to match [email protected] API
  Relaxed eslint rule no-unused-expressions (facebook#724)
  Fix the doc
  Publish
  Add 0.6.1 changelog
  Moved Babel and ESLint config to package.json after ejecting (facebook#773)

Conflicts:
	packages/react-scripts/package.json
@lock lock bot locked and limited conversation to collaborators Jan 22, 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.

4 participants