Awesome
Dart Sass for Spockets
Use Dart Sass with Sprockets and the Ruby on Rails asset pipeline.
This gem is a fork of sass/sassc-rails which maintains API compatibility but delegates to the sass-embedded gem which uses Dart Sass instead of the libsass C implmentation.
For ease of upgrading, the root namespace ::SassC
is still used by this gem,
although it is now a misnomer. This is planned to be renamed in a future
major version release.
Installation
Add this line to your application's Gemfile:
gem 'dartsass-sprockets'
This will automatically configure your default Rails
config.assets.css_compressor
to use :sass
.
Version Support
The current version of dartsass-sprockets
supports:
- Ruby 3.1+
- Rails 6.1+
For older versions of Ruby and Rails may be supported with earlier versions of this gem.
Upgrading to Dart Sass
This gem is a drop-in replacement to sass-rails. Note the following differences:
- This library does not apply SASS processing to
.css
files. Please ensure all your SASS files have file extension.scss
. config.sass.style
values:nested
and:compact
will behave as:expanded
. Use:compressed
for minification.config.sass.line_comments
option is ignored and will always be disabled.
Inline Source Maps
To turn on inline source maps, add the following configuration
to your development.rb
file:
# config/environments/development.rb
config.sass.inline_source_maps = true
After adding this config line, you may need to clear your assets cache
(rm -r tmp/cache/assets
), stop Spring, and restart your Rails server.
Note these source maps are inline and will be appended to the compiled
application.css
file. (They will not generate additional files.)
Alternatives
- dartsass-rails: The Rails organization maintains its own wrapper for Dart Sass. Unlike this gem, dartsass-rails does not support Sprockets.
Credits
- This gem is maintained and used in production by TableCheck. (We'd be very glad if the Sass organization could take over maintainership in the future!)
- Thank you to Natsuki for the sass-embedded gem.
- Credit to Ryan Boland and the authors of the original sass/sassc-rails and sass-rails gems.
- See our awesome contributors.
Contributing
- Fork it (https://github.com/tablecheck/dartsass-sprockets/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - try to include tests - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request