Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic Sass processing in Rails 7

I'm confused about the idiomatic way to process Sass in Rails 7.

The README.md for the importmap-rails repo says:

This frees you from needing Webpack, Yarn, npm, or any other part of the JavaScript toolchain. All you need is the asset pipeline that's already included in Rails.

and The Rails Guide to The Asset Pipeline states that:

Rails can easily work with Sass by adding the sassc-rails gem to your Gemfile, which is used by Sprockets for Sass compilation

But in October 2020 we learned that LibSass is Deprecated, and that we should be using Dart Sass instead.

The sassc-rails gem is based on LibSass.

Hence should we be using something else to process Sass? And if so is the documentation on the Rails 7 asset pipeline misleading?

I'm relatively new to Rails and my naive reading of The README.md and The Asset Pipeline Guide led me to think that we should be using "the asset pipeline that's already included in Rails" to compile Sass and did not need "Yarn, npm, or any other part of the JavaScript toolchain".

What is the Rails 7 idiomatic way to process Sass?

like image 269
dumbledad Avatar asked Nov 28 '25 14:11

dumbledad


1 Answers

(Copied directly from DHH's reply to the GitHub Issue.)

There are two ways to use Dart Sass in Rails. Either through cssbundling-rails with Node. Or with https://github.com/rails/dartsass-rails, using the standalone Dart Sass compiler, without node. If you're doing a default Rails 7 app that uses import maps, you should do the latter.

We need to update the asset pipeline guide and other documentation to recognize this.

like image 104
dumbledad Avatar answered Nov 30 '25 05:11

dumbledad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!