It’s now 2021, we’ve upgraded Rails a few times, and a ticket to “finish the move to Webpacker” landed on my pair and I. After a lot of searching the internet, copious floundering and cursing, we completed the story in a manner of speaking. It was not easy. Hopefully, this post can help someone save a bit of time.
8 things to know about moving from Asset Pipeline (which uses Sprockets) to Webpacker in Rails:
Seventh, Node.js has serious opinions about scope. This means old-style JS that is used to everything being in the global space will not be able to talk with Node JS unless that code is explicitly exposed globally. Generally, it is considered better to re-write in Node style any old JS that needs to communicate with Node JS code.
Eighth, Ross Kaffenberger’s website is an amazing resource on this subject. He’s compiled his blog posts about Rails, Webpacker, and the Asset Pipeline at https://rossta.net/webpack-on-rails/ This deep dive into all the settings contained in webpacker.yml helped me solve a 2 year old problem in my codebase: https://rossta.net/blog/how-to-use-webpacker-yml.html
To sum up: Moving from old-style JS to Webpack and Node should be an iterative process. Find the seams (see Michael Feathers “Working Effectively with Legacy Code”) and move chunks one at a time to give your QA a chance at catching all the bugs you will create. Many stories make the labor, if not light, then perhaps less crushing.