openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.11k stars 723 forks source link

Replace rails/webpacker #10298

Open dacook opened 1 year ago

dacook commented 1 year ago

We use the gem rails/webpacker, which has been retired. Some of its dependencies already have security warnings and can't be automatically updated (eg loader-utils), because webpacker locks to the older versions.

The webpacker readme provides a few suggestions on how to proceed.


Edit: consensus is to try jsbundling-rails

mkllnk commented 1 year ago

We moved all assets into the webpacker directory to manage it there. I reckon that we should revert that one by one and tackle the Javascript part last. We will be reverting a lot of this pull request:

It has 51 commits and many of them deal with individual packages like Foundation and jQuery. It may be useful to have a hybrid system for a while. I picked relevant commits here in reverse order to act on:

abdellani commented 1 year ago

From the article, there are three alternatives:

  1. importmap-rails the default approach that will be used on Rails 7.
  2. jsbundling-rails

    If you're on Webpacker today, it's a very modest jump to switch to one of the bundlers made available through the jsbundling-rails gem. You don't even have to stick with Webpack. Fundamentally, they all work in the same way: take an entry point, produce a build. We've initially taken that path with Basecamp 3, converting from Webpacker to esbuild. But with HEY, we took the full step of going straight to import maps. Neither choice involved a lot of effort. The JavaScript is still the JavaScript. You're mostly adjusting a few import paths.

  3. Separate the backend (Rails API) and the frontend ( I don't think that this is an option for us since we are moving to stimulus)

From what I can see, the first approach will be the best fit when AngularJs will be removed.

In the meantime, while it's still possible to use the first on the presence on AngularJS, I'm not sure if we should use jsbundling-rails.

mkllnk commented 1 year ago

jsbundling-rails seems to be closer to what we do at the moment. So I would start there. We do have JS templates which contain Ruby code. And I believe, but I may be wrong, that importmaps-rails doesn't support this mix.

abdellani commented 10 months ago

How about using shakapaker? @openfoodfoundation/developers

mkllnk commented 10 months ago

How about using shakapaker?

Yes, that would be the easiest path forward for now because it offers backwards-compatibility with webpacker. Long-term, I would like to get closer to the original Rails asset pipeline with sprockets and importmap. Default packages are often better maintained and tested. And Rails usually picks very good defaults which are still quite simple and robust while offering everything you need.

Anyway, if we can't jump straight back to the defaults then we should transition to Shakapacker for now.