Guide to Rails 7 and the Asset Pipeline

What is the state of this guide? The merge request does not cover many of the points above. I think it is a really good idea, since there is a lot of confusion on this topic.

It pretty much comes down to the block below. If you want more details on why, I gave a talk about this topic at RailsWorld and that should probably be available soon at the official youtube channel.

2 Likes

I would add that it also seems to become possible to do JavaScript bundling without node/yarn by using bun instead?

I actually have to update that, as itā€™s more about ā€œno-buildā€ or ā€œall the buildsā€, instead of node specifically. :sweat_smile:

1 Like

I no longer have permission to edit my original post, so Iā€™ll post this here. Itā€™s my Rails World talk where I explain how to old asset pipeline worked, how the new one works, and why you should be using the gems in my TL:DR.

8 Likes

Hey, thanks for the guide! It did indeed cleared a few things. :slight_smile:

Iā€™d like to ask for help to clarify one question thoughā€¦

Weā€™ve recently upgraded an old rails app from Rails 5 to Rails 7, skipping Rails 6 step completely (mainly because of webpacker). Upgrading Sprockets from 3 to 4 required way more effort than we initially anticipated, so weā€™ve stayed with Sprockets v3 - because, hey, it just works. Donā€™t fix whatā€™s not broken, you knowā€¦
Weā€™re also using Coffeescript, if that matters.

Now weā€™d like to introduce Turbo to this app.

There are plenty of guides on how to make Turbo work with webpack, with importmaps, with jsbundling, and whatnotā€¦ but none regarding Sprockets 3. Soooā€¦ is it possible at all? Without adding any transpliers, builders, or other things like esbuild & node shtuff, if thatā€™s possible, of course.

On a side note, Stimulus install guide says that it can be used without a build system at all. Does Turbo support this approach as well (using the gem to add server side bits and bobbles, and adding some plain js to layout so the browser takes care of the rest)?

Iā€™ve stopped using Sprockets for JS years ago, so I canā€™t help much with that.

That said, yes, Turbo can be used without a build system. DHH is curently dedicating himself to ensuring that all parts of the Rails JS libraries works perfectly without a build system at all.

1 Like

Ah, thatā€™s some good news, thank you! :slight_smile:

Iā€™ve managed to get Turbo to work with Sprockets 3.

After bundling the turbo-rails gem, adding this to the <html><head> did the trick:

<%= javascript_include_tag "turbo", type: "module" %>
<script type="module">
  import {Turbo, cable} from "<%= asset_path("turbo") %>"
  Turbo.session.drive = false
</script>

(I prefer to start with Turbo disabled by default, and then enable it step by step)

Thank you for your help. :slight_smile:

3 Likes

That would be me, thanks!