Upgrade Sprockets 3 to 4 in a Rails project

Updated . Posted . Visible to the public.

There's a update guide at https://github.com/rails/sprockets/blob/master/UPGRADING.md Show archive.org snapshot

In short, must replace Rails.application.config.assets.precompile entries with link statements in Sprockets' manifest.js file.

Example: app/assets/stylesheets/frontend/all.sass and app/assets/stylesheets/backend/all.sass should be precompiled.

Sprockets 3:

Rails.application.config.assets.precompile += %w[
  backend/all.css
  frontend/all.css
]

Sprockets 4 manifest.js:

//= link_tree ../images
//= link backend/all.css
//= link frontend/all.css

If you get couldn't find file 'base.sass' with type 'text/css' errors, replace something like

*= require base.sass

with:

*= require base

in your sass files.

Judith Roth
Last edit
Judith Roth
Posted by Judith Roth to Judith's Dev Notes (2021-10-16 17:48)