ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

Webpack support for Rails


#1

Use Webpack to manage app-like JavaScript modules in Rails

I’d suggest the following:

Provide Rails support for the webpack module bundler for client-side assets.

  1. Provide no interference with the legacy Asset Pipeline. /app/assets contains files used by the Asset Pipeline.
  2. Provide controller helpers for getting the path to the created webpack JavaScript or CSS bundles.
  3. Provide view helpers for exposing webpack created JavaScript and stylesheet tag helpers that are the webpack equivalents of the javascript_include_tag and the stylesheet_link_tag. These view helpers are smart enough to understand the 3 modes of running webpack to create assets:
  4. Static files created for development.
  5. Running the webpack-dev-server for providing hot-reloadable files for development.
  6. Static, hashed files created for production deployment, using the chunkhash technique for asset caching.
  7. Via the Rails /config/webpack.rb, Allow configuration of the controller and view helpers in a convenient manner that does not mandate any particular location of the webpack configuration files nor the subdirectory under the /public directory for deployment.

A gem like the above can be usable for any Rails 3.x and greater project.

Optional for Rails 5.1

  • Provide a generator to create the simplest possible example of using Webpack for assets.

Out of Scope

  • Integrations with other JavaScript frameworks, such as React, Angular, etc. These can be done in other gems.
  • Anything beyond a basic webpack config, as the maintenance of this config would be far greater than the basics needed to support the scope of the gem.

#2

Posted: