How to use Propshaft with Rails 8
Recently, the first beta version of Rails 8 has been released, and with it, Propshaft has become the default asset pipeline.
Propshaft works quite differently to Sprockets. Mainly, all compilation, minification und concatenation tasks are outsourced to separate gems. The asset pipeline itself is only responsible for loading the assets and fingerprinting them, so they can be cached indefinitely.
By default, Propshaft is configured to serve assets from app/assets
, lib/assets
and vendor/assets
. They are served directly in development mode, and copied to public/assets
in production mode.
Here are some common use cases and how to solve them.
Serving static CSS files
In order for Propshaft to find static CSS files, you can place them either app/assets/stylesheets
(if you wrote them yourself) or in vendor/assets/stylesheets
(if they are part of a library or plugin). Both locations are searched for by Propshaft.
To link the CSS files from your frontend, you can use the stylesheet_link_tag
helper and pass the file name:
<%= stylesheet_link_tag 'bootstrap-5.3.3.min.css', "data-turbo-track": "reload" %>