-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Consistently use NODE_ENV and support non-standard env #1304
Conversation
lib/webpacker.rb
Outdated
@@ -2,6 +2,9 @@ | |||
require "active_support/logger" | |||
require "active_support/tagged_logging" | |||
|
|||
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" | |||
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"] |
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 probably don't want to set any ENV
vars here since this file gets required by applications. It was OK to do in bin/* files since those are separate one-off processes.
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.
Ahh right, I was thinking setting here will set it in all environments (like in rails console) but I guess that's not ideal.
Does this allow |
Yep it was possible before as well except that we were falling back to RAILS_ENV if there was no NODE_ENV set. I removed that case for clarity so it always checks for NODE_ENV first and then falls back to 'production'. What do you think? |
941ad77
to
0d08ab4
Compare
What happens when there's no config/webpack/[environment].js file matching the env? I can't tell at a glance. |
The one thing I am unsure is: If we open rails console without That's why I moved the env declaration to module itself from binstubs so |
My Circle CI test was failed with following message:
We expect webpacker to fallback If this is breaking change please update minor(or major) version.. |
@hiromi2424 Ahh I see, what is NODE_ENV set to |
@gauravtiwari It passed with
LET
ACTSIt fallbacks I think raising error is not comfortable decision since webpacker is for rails application that requires |
I highly endorse the idea of using RAILS_ENV as a fallback for NODE_ENV. |
alright makes sense, will push an update 👍 |
1a5b921
to
76d5f16
Compare
76d5f16
to
e06d565
Compare
Huge thanks! @gauravtiwari |
The Rails defined custom env is allowed by rails#1304. However Webpacker custom env is not allowed for now. ``` /Users/tricknotes/dummy-app/node_modules/@rails/webpacker/package/config.js:16 delete defaults.extensions ^ TypeError: Cannot convert undefined or null to object ``` This commit allows using user defined env for Webpacker.
The Rails defined custom env is allowed by rails#1304. However Webpacker custom env is not allowed for now. ``` /Users/tricknotes/dummy-app/node_modules/@rails/webpacker/package/config.js:16 delete defaults.extensions ^ TypeError: Cannot convert undefined or null to object ``` This commit allows using user defined env for Webpacker.
The Rails defined custom env is allowed by rails#1304. However Webpacker custom env is not allowed for now. ``` /Users/tricknotes/dummy-app/node_modules/@rails/webpacker/package/config.js:16 delete defaults.extensions ^ TypeError: Cannot convert undefined or null to object ``` This commit allows using user defined env for Webpacker.
@gauravtiwari What would be the expected way to provide a different webpacker config in custom environment ? The typical use case would be using different JS API keys. Currently I'm using different sections in environment.plugins.append('Define', new webpack.DefinePlugin({
"GA_PROPERTY_ID": JSON.stringify(config.ga_property_id),
....
})); |
@Systho Sorry about that, I am working on a PR to fix this. |
No problem, It's great that you're aware of the problem. Keep up the good work and thank you ! |
Closes #1265
This PR fixes issue for non-standard environments
ConfigList
typecc// @rmehner @IgorDmitriev @doits @hiromi2424 do you wanna try out this branch please?