Skip to content

Commit bde99e5

Browse files
authored
Install dartsass-rails when generating app with sass (rails#47545)
1 parent 05dc093 commit bde99e5

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ gem "jsbundling-rails"
2424
gem "cssbundling-rails"
2525
gem "importmap-rails"
2626
gem "tailwindcss-rails"
27+
gem "dartsass-rails"
2728
# require: false so bcrypt is loaded only when has_secure_password is used.
2829
# This is to avoid Active Model (and by extension the entire framework)
2930
# being dependent on a binary library.

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ GEM
168168
railties (>= 6.0.0)
169169
dalli (3.2.3)
170170
dante (0.2.0)
171+
dartsass-rails (0.4.1)
172+
railties (>= 6.0.0)
171173
date (3.3.3)
172174
debug (1.7.1)
173175
irb (>= 1.5.0)
@@ -540,6 +542,7 @@ DEPENDENCIES
540542
connection_pool
541543
cssbundling-rails
542544
dalli (>= 3.0.1)
545+
dartsass-rails
543546
debug (>= 1.1.0)
544547
delayed_job
545548
delayed_job_active_record

guides/source/working_with_javascript_in_rails.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ that you should choose a traditional bundler include:
135135
[tree-shaking](https://webpack.js.org/guides/tree-shaking/).
136136
* If you will install Bootstrap, Bulma, PostCSS, or Dart CSS through the
137137
[cssbundling-rails gem](https://github.com/rails/cssbundling-rails). All options provided by this
138-
gem except Tailwind will automatically install `esbuild` for you if you do not specify a different
138+
gem except Tailwind and Sass will automatically install `esbuild` for you if you do not specify a different
139139
option in `rails new`.
140140

141141
Turbo

railties/lib/rails/generators/app_base.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,10 @@ def dockerfile_deploy_packages
546546
packages.sort
547547
end
548548

549-
# CSS processors other than Tailwind require a node-based JavaScript environment. So overwrite the normal JS default
549+
# CSS processors other than Tailwind and Sass require a node-based JavaScript environment. So overwrite the normal JS default
550550
# if one such processor has been specified.
551551
def adjusted_javascript_option
552-
if options[:css] && options[:css] != "tailwind" && options[:javascript] == "importmap"
552+
if options[:css] && options[:css] != "tailwind" && options[:css] != "sass" && options[:javascript] == "importmap"
553553
"esbuild"
554554
else
555555
options[:javascript]
@@ -561,6 +561,8 @@ def css_gemfile_entry
561561

562562
if !using_node? && options[:css] == "tailwind"
563563
GemfileEntry.floats "tailwindcss-rails", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]"
564+
elsif !using_node? && options[:css] == "sass"
565+
GemfileEntry.floats "dartsass-rails", "Use Dart SASS [https://github.com/rails/dartsass-rails]"
564566
else
565567
GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]"
566568
end
@@ -673,6 +675,8 @@ def run_css
673675

674676
if !using_node? && options[:css] == "tailwind"
675677
rails_command "tailwindcss:install"
678+
elsif !using_node? && options[:css] == "sass"
679+
rails_command "dartsass:install"
676680
else
677681
rails_command "css:install:#{options[:css]}"
678682
end

railties/test/generators/app_generator_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,12 @@ def test_css_option_with_asset_pipeline_tailwind
868868
end
869869
end
870870

871+
def test_css_option_with_asset_pipeline_sass
872+
run_generator_and_bundler [destination_root, "--css=sass"]
873+
assert_gem "dartsass-rails"
874+
assert_file "app/assets/stylesheets/application.scss"
875+
end
876+
871877
def test_css_option_with_cssbundling_gem
872878
run_generator_and_bundler [destination_root, "--css=postcss"]
873879
assert_gem "cssbundling-rails"

0 commit comments

Comments
 (0)