Skip to content

Commit 990e297

Browse files
authored
Merge pull request #19 from jacob-carlborg-apoex/migrate-from-sass-rails
Add instructions how to migrate from sass-rails
2 parents 5719168 + 588df2d commit 990e297

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ When you're developing your application, you want to run Dart Sass in watch mode
1616
1. Run `./bin/bundle add dartsass-rails`
1717
2. Run `./bin/rails dartsass:install`
1818

19-
2019
## Building in production
2120

2221
The `dartsass:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Dart Sass output will be generated.
@@ -39,6 +38,79 @@ The hash key is the relative path to a Sass file in `app/assets/stylesheets/` an
3938
## Importing assets from gems
4039
`dartsass:build` includes application [assets paths](https://guides.rubyonrails.org/asset_pipeline.html#search-paths) as Sass [load paths](https://sass-lang.com/documentation/at-rules/use#load-paths). Assuming the gem has made assets visible to the Rails application, no additional configuration is required to use them.
4140

41+
## Migrating from sass-rails
42+
43+
If you're migrating from [sass-rails](https://github.com/rails/sass-rails)
44+
(applies to [sassc-rails](https://github.com/sass/sassc-rails) as well)
45+
and want to switch to dartsass-rails, follow these instructions below:
46+
47+
1. Remove the sass-rails gem from the Gemfile by running
48+
49+
```
50+
./bin/bundle remove sass-rails
51+
```
52+
53+
1. Install dartsass-rails by following the
54+
[Installation](#installation) instructions above
55+
56+
1. Remove any references to Sass files from the Sprockets manifest file:
57+
`app/assets/config/manifest.js`
58+
59+
1. In your continues integration pipeline, before running any tests that
60+
interacts with the browser, make sure to build the Sass files by running:
61+
62+
```
63+
bundle exec rails dartsass:build
64+
```
65+
66+
## Troubleshooting
67+
68+
Some common problems experienced by users ...
69+
70+
### LoadError: cannot load such file -- sassc
71+
72+
The reason for the above error is that Sprockets is trying to build Sass files
73+
but the sass-rails or sassc-rails gems are not installed. This is expected,
74+
since Dart Sass is used instead to build Sass files, and the solution is
75+
to make sure that Sprockets is not building any Sass files.
76+
77+
There are three reasons for why this error can occur:
78+
79+
#### Sass files are referenced in the Sprockets manifest file
80+
81+
If any Sass files are referenced in the Sprockets manifest file
82+
(`app/assets/config/manifest.js`) Sprockets will try to build the Sass files and
83+
fail.
84+
85+
##### Solution
86+
87+
Remove any references to Sass files from the Sprockets manifest file. These are
88+
now handled by Dart Sass. If you have more Sass files than `application.scss`,
89+
make sure these are compiled by Dart Sass
90+
(see [Configuring builds](#configuring-builds) above).
91+
92+
#### Running locally
93+
94+
If you receive this error when running the Rails server locally and have
95+
already removed any references to Sass files from the Sprockets manifest file,
96+
the Dart Sass process is most likely not running.
97+
98+
##### Solution
99+
100+
Make sure the Dart Sass process is running by starting the Rails sever by
101+
running: `./bin/dev`.
102+
103+
#### Running continues integration pipelines
104+
105+
If you receive this error when running tests that interacts with the browser in
106+
a continues integration pipeline and have removed any references to Sass files
107+
from the Sprockets manifest file, the Sass files have most likely not been
108+
built.
109+
110+
##### Solution
111+
112+
Add a step to the continues integration pipeline to build the Sass files with
113+
the following command: `bundle exec rails dartsass:build`.
42114
43115
## Version
44116

0 commit comments

Comments
 (0)