never gives a comprehensible overview, picture of what is going on.
When in doubt, what I do is I run rails new myapp
and have a look how things look, then compare with the app that I want to upgrade.
I have not yet really understood wether app/assets/javascripts has completely been moved to app/javascripts
I upgraded my app to Rails 7 and now have all JS in app/javascript
. I have an entry point app/javascript/application.js
and another app/javascript/admin.js
. They have regular ES6 syntax, no //= require
directives.
//= require rails-ujs
In the beginning I also still used Rails UJS and included it like import Rails from “@rails/ujs”; Rails.start()
from the application.js. Then I progressively converted all the forms to Turbo (import * as Turbo from "@hotwired/turbo"
+ Turbo.session.drive = false;
in application.js + adding data: { turbo: true }
on the individual forms), then I finally removed Rails UJS completely and am now in the process of enabling Turbo Drive application-wide.
Similar difficulties with the asset pipeline.
The Sprockets asset pipeline is there like before, by default. Although the longer term plan is to replace it with Propshaft. My app still uses Sprockets and I don’t remember particular difficulties on that front when upgrading to Rails 7. It is mainly configured with app/assets/config/manifest.js
.
first create things in products, and then pack them together.
I’m not sure what “products” and “pack” means here. The default in Rails 7 is not to bundle JS files at all, the asset pipeline only minifies, zips and fingerprints the files. Then those JS files are referenced from the HTML head using an import map. In our own app we got some issues with import maps and decided to use jsbundling-rails with esbuild, which we are happy with. This way the JS is bundled and it is much faster than webpack that we also used at some point. Anyway, whether using importmaps, jsbundling-rails or webpack (via webpacker or shakapacker), in all cases Sprockets doesn’t take care of bundling the JS any more. And relatively soon (even now if you want to try), it should disappear as propshaft should take care of the remaining responsibilities.
(Someone please comment me if I’m saying something wrong…)
Even in development mode I have to run assets:precompile to get things running.
What does it mean “to get things running”? I would try to decide if you want importmaps, jsbundling-rails or webpacker/shakapacker and see where that leads you. Then you might be able to ask more specific questions. You could also compare with a new Rails app (using the various options to choose between importmap, jsbundling, etc) to see how things should be organised.