rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.31k stars 1.47k forks source link

Use single webpack config, /webpack.config.js for rails/webpacker, matching jsbundling-rails #3240

Closed justin808 closed 2 years ago

justin808 commented 2 years ago

What?

Let's have the webpack config for rails/webpacker match jsbundling-rails and use /webpack.config.js.

Why?

KISS, DRY

  1. Simplicity and DRY. The default install was already cleaned up so there are no differences between installing test.js, development.js, and prododuction.js. This is just more clutter for people to dig through.
  2. Avoid confusion. Most rails developers think about the RAILS_ENV. It's not at all obvious that old configuration file used was based on the NODE_ENV. And what if you wanted to adjust the configuration based on the RAILS_ENV. Surely, you could have gotten confused. Additionally, the default of using NODE_ENV for building a Node file was also non-obvious.
  3. Easy upgrade. The upgrade from using the old files to the new configuration only requires copy/pasting a few lines of code into the new configuration file.

Demo of the migration

Single change in shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh

Visual of the current, more complicated flow

Here is a clip from my slides from my past RailsConf talk on the topic:

image

justin808 commented 2 years ago

I think that it's worth considering having the having the default webpack config match https://github.com/rails/jsbundling-rails (and webpack's default):

So we can have the default be /webpack.config.js.

Agree? If so, I'll make the change.

CC: @guillaumebriday

justin808 commented 2 years ago

Merged: https://github.com/shakacode/shakapacker/pull/5.