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

Detangle NODE_ENV and RAILS_ENV #1359

Merged
merged 1 commit into from
Mar 20, 2018
Merged

Detangle NODE_ENV and RAILS_ENV #1359

merged 1 commit into from
Mar 20, 2018

Conversation

gauravtiwari
Copy link
Member

@gauravtiwari gauravtiwari commented Mar 15, 2018

In earlier versions of webpacker we have used Rails env as fallback env, which isn't ideal because both NODE_ENV and RAILS_ENV has different meaning for different environments.

For example: setting NODE_ENV=production means the webpacker will compile assets in production mode however at same time RAILS_ENV can be staging. Webpack and node libraries only understands development and production environments. However, it's normal to have many custom RAILS_ENV.

This PR makes RAILS_ENV and NODE_ENV independent of each other for clarity.


Examples:

# will compile in production mode but will use staging settings from webpacker.yml (if present or else fallback to production config)
RAILS_ENV=staging bundle exec rails webpacker:compile
# will use foo env settings from webpacker.yml but will compile in production mode
RAILS_ENV=foo bundle exec rails webpacker:compile

By default binstubs will use NODE_ENV=development however rake compile task will compile in production mode:

# Compiles in development mode by default
./bin/webpack
./bin/webpack-dev-server
# Compiles in production mode
NODE_ENV=production ./bin/webpack
NODE_ENV=production ./bin/webpack-dev-server
# compiles in production mode by default (unless NODE_ENV is supplied) - same as sprockets
bundle exec rails assets:precompile
bundle exec rails webpacker:compile

TODO:

  • Fix tests

@gauravtiwari gauravtiwari force-pushed the custom-env branch 2 times, most recently from 8bb25f3 to 01c6bc0 Compare March 18, 2018 21:31
@@ -14,14 +14,14 @@ def run
private
def load_config
@config_file = File.join(@app_path, "config/webpacker.yml")
dev_server = YAML.load_file(@config_file)[ENV["NODE_ENV"]]["dev_server"]
dev_server = YAML.load_file(@config_file)[ENV["RAILS_ENV"]]["dev_server"]
Copy link
Contributor

Choose a reason for hiding this comment

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

THIS !
Thank you very much for having thought of this :)

@tricknotes
Copy link
Contributor

@gauravtiwari
This PR is pretty awesome!
Could you release a new version with this change?

@gauravtiwari
Copy link
Member Author

Made a new release 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants