A guide for Webpacker?

Despite my protestations I’m seen as A Rails Expert within my organisation. And I’ve been fielding a ton of questions re. JS asset management, due to the switch to Webpacker.

Webpack is tremendously powerful and Webpacker is a helpful manager and wrapper. However, Webpack itself is also a Heath Robinson machine and trying to configure/debug it in many common cases immediately becomes a voyage into the arcane.

Neither of these Rails Guides currently make any mention of Webpack or Webpacker: The Asset Pipeline - The Asset Pipeline — Ruby on Rails Guides Working with JavaScript in Rails - Working with JavaScript in Rails — Ruby on Rails Guides

I don’t think it’s unreasonable to suggest that they should both deal with relevant aspects.

The 6.0 upgrade guide (Upgrading Ruby on Rails — Ruby on Rails Guides) makes it seem that an upgrade is as simple as adding a gem and running a task, but for many existing applications it will be very far from trivial.

None of this is meant to detract from what’s already there - the Webpacker gem itself has many useful docs and a pretty good README, but they’re mostly written from a different perspective to that of a guide. In particular there’s often assumption of familiarity with Webpack, and many docs are thorough references rather than introductory guides.

For all I know there may be a new guide in progress, but I couldn’t see a PR or issue. It’s something I’d be interested in at contributing to, if only for the selfish reason of reducing my own burden.

2 Likes

Hello Josh, I’m from the webpack side of the equation.

It’s something I’d be interested in at contributing to, if only for the selfish reason of reducing my own burden.

A PR would greatly be appreciated! Here are some off-the-cuff topics that I see coming up often on the issue tracker:

  • “I already know what my webpack.js exports need to be, how do I convert that to webpackER?”
  • “Webpacker comes with node sass but I need to use dart sass”
  • :star: How package.json (unintuitively) acts differently than a gemfile (and how it can ruin your day)
  • “I need to use webpack-dev-server to deploy my stuff” (don’t do this)
  • :star:Misunderstandings about what should be in a “pack”. Users who make every individual js file a new pack will find that every pack can come at an expediential cost performance/size/buildtime depending on how much library code is duplicated.
  • How does json/data from server to packed js
  • NODE_ENV vs RAILS_ENV
  • When to use a file.js.erb and when to use a filePack.js (and how those communicate with each other)
  • There are times where you need to ignore install instructions from JS library READMEs Hope this is helpful for a potential guide. If you have any questions feel free to email.

Have there been any updates on this? A guide to implementing webpack in rails would be quite useful!

A guide has been added Webpacker — Ruby on Rails Guides