Why does the rails/webpacker gem depend on both the RAILS_ENV and NODE_ENV values?
Both the JS and Ruby code of rails/webpacker uses the RAILS_ENV to find the applicable section of the config/webpack YAML file. This YAML file is the glue between the JS code that configures webpack and the Rails view helpers.
The JS code that creates the webpack configuration object uses the NODE_ENV to find the default configuration as well as the customizable configuration in the config/webpack directory, such as using config/webpack/production.js for NODE_ENV production.
The Ruby code of rails/webpacker’s view helpers use the RAILS_ENV to get values out of this config/webpacker.yml to configure the view helpers to use the right directory and other aspects that configure the Rails server and what is sent to the browsers in the HTML sent.
Here’s where webpacker picks the Rails.env for the view helpers.