-
-
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
add webpack-env-define-plugin package #1030
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 - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
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.
Overall looks good. The show stopper is really the way that react-scripts is referencing the webpack plugin.
@@ -6,3 +6,4 @@ my-app* | |||
template/src/__tests__/__snapshots__/ | |||
lerna-debug.log | |||
npm-debug.log | |||
.idea/ |
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.
Add .idea to your global .gitignore not this one. See https://help.github.com/articles/ignoring-files/ for details
// Assert this just to be safe. | ||
// Development builds of React are slow and not intended for production. | ||
if (env['process.env'].NODE_ENV !== '"production"') { | ||
throw new Error('Production builds must have NODE_ENV=production.'); |
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.
Why did you remove this throw?
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 changed the default for NODE_ENV in webpack.config.prod.js
to be production
so the risk of running a production build with NODE_ENV !== 'production'
is low.
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 wouldn't say it's low. People try to run NODE_ENV=my-server npm run build
all the time and get non-prod builds by mistake.
@@ -64,6 +64,7 @@ | |||
"url-loader": "0.5.7", | |||
"webpack": "1.13.2", | |||
"webpack-dev-server": "1.16.2", | |||
"webpack-env-define-plugin": "../webpack-env-define-plugin", |
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.
Don't reference a local path. Refer to the package the way it would appear on npmjs.com
See https://github.com/lerna/lerna for more details on how these packages link together.
@@ -0,0 +1,14 @@ | |||
{ |
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.
You should add yourself as a contributor to the package.json. See http://browsenpm.org/package.json#contributors for details.
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.
done
Ooh, I like this. But can we move this into |
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 move it into react-dev-utils
.
@gaearon done! |
@@ -28,6 +29,7 @@ | |||
"html-entities": "1.2.0", | |||
"opn": "4.0.2", | |||
"sockjs-client": "1.0.3", | |||
"strip-ansi": "3.0.1" | |||
"strip-ansi": "3.0.1", | |||
"webpack": "^1.13.3" |
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.
There isn't an explicit webpack dependency to support both 1.x and 2.x.
See #963 and #950 (comment) for more info.
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.
@gaearon what do you want to do regarding the webpack dependency?
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.
You can remove it.
@@ -201,3 +201,35 @@ module.exports = { | |||
// ... | |||
} | |||
``` | |||
|
|||
#### `new webpackEnvDefinePlugin({regex: string, customVariables: Object.<string, string>})` |
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 webpack
prefix.
regex: /^MY_PREFIX_/i, | ||
customVariables: { | ||
// Useful for determining whether we’re running in production mode. | ||
// Most importantly, it switches React into the correct mode. |
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.
Both of these comments are a bit out of context (and the second one is actually misleading).
Can we come up with better realistic examples?
// Assert this just to be safe. | ||
// Development builds of React are slow and not intended for production. | ||
if (env['process.env'].NODE_ENV !== '"production"') { | ||
throw new Error('Production builds must have NODE_ENV=production.'); |
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 wouldn't say it's low. People try to run NODE_ENV=my-server npm run build
all the time and get non-prod builds by mistake.
// Useful for determining whether we’re running in production mode. | ||
// Most importantly, it switches React into the correct mode. | ||
'NODE_ENV': JSON.stringify( | ||
process.env.NODE_ENV || 'development' |
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.
We don't need to read process.env.NODE_ENV
here at all. We don't allow overriding it. So we can just pass 'development'
.
// Useful for determining whether we’re running in production mode. | ||
// Most importantly, it switches React into the correct mode. | ||
'NODE_ENV': JSON.stringify( | ||
process.env.NODE_ENV || 'production' |
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.
Same here. Just pass 'production'
?
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.
You'd need to update comments to make sense after the changes.
@gaearon I fixed the issues you referred to but removing the
Should I remove the |
@gaearon, removed the webpack.DefinePlugin dependency |
Hey, sorry for the trouble. I think we won't go ahead with this after all. 😞 We've been changing how env variables work recently (since they're also useful in I'm sorry I didn't realize this earlier. |
I found this code useful for our project configuration solution.
I didn't want to duplicate it so thought it could be wrapped in a handy webpack plugin.