Webpacker: Why default environment set to 'production'?

Created on 26 Dec 2019  路  5Comments  路  Source: rails/webpacker

Here default environment set to 'production', Is there any specific reason this has been set.
https://github.com/rails/webpacker/blob/master/lib/webpacker/env.rb#L2

Can we set RAILS_ENV or RACK_ENV or 'development' should be our default environment. Because most of the application use 'development' would be there default environment.

duplicate

All 5 comments

development and test environments are taken care of in the webpacker.yml. If your RAILS_ENV is one of those, everything will be fine (it uses Rails.env first). What webpacker _cannot guess_ is what webpacker settings you'd like when you're not in one of those three defaults. Let's say you have a staging RAILS_ENV, what would you like the webpacker settings to be? I'd prefer production settings since dev and test may be special cases, but any other hosted environment should compile webpack in the manner of production, no?

ci as a RAILS_ENV could be an exception, but honestly, I think you'll want to webpack compile with the production settings in CI because, well, you're trying to determine if the code is production-ready and that would be the best emulation.

is your specify a staging environment, you should have a staging.js configuration file, and webpacker should pick that up like every other thing in the Rails eco-system.

I don't think staging is a common NODE_ENV. Since we're talking about what NODE_ENV should be inferred from a RAILS_ENV=staging, my opinion is that it makes sense to default to NODE_ENV=production. If you compile assets differently for staging, you could totally make a staging.js file and be on your way. IMO the purpose of RAILS_ENV=staging is to act like production, so compiling javascript _like production_ seems like a good default.

And from a Rails point of view that's wrong.
In the entire Rails stack if a custom environment is specified, than all tools need to follow that and act accordingly.

This is discussed at length here https://github.com/rails/webpacker/issues/1212#issuecomment-442228316. I encourage further discussion to take place there or in a PR with the changes suggested.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eearslya picture Eearslya  路  3Comments

suhomlineugene picture suhomlineugene  路  3Comments

itay-grudev picture itay-grudev  路  3Comments

suhomozgy-andrey picture suhomozgy-andrey  路  3Comments

eriknygren picture eriknygren  路  3Comments