Skip to content

Commit c570e03

Browse files
committed
Add an option to add extra load paths
1 parent 3ff15ea commit c570e03

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Rails.application.config.dartsass.builds = {
3636

3737
The hash key is the relative path to a Sass file in `app/assets/stylesheets/` and the hash value will be the name of the file output to `app/assets/builds/`.
3838

39+
By default, only files under `app/assets/stylesheets` will be watched. If you'd like to add extra directories, use the `Rails.application.config.dartsass.extra_load_paths` configuration array.
40+
41+
```
42+
# config/initializers/dartsass.rb
43+
Rails.application.config.dartsass.extra_load_paths = ["app/components"]
44+
```
3945

4046
## Version
4147

lib/dartsass/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module Dartsass
44
class Engine < ::Rails::Engine
55
config.dartsass = ActiveSupport::OrderedOptions.new
66
config.dartsass.builds = { "application.scss" => "application.css" }
7+
config.dartsass.extra_load_paths = []
78
end
89
end

lib/tasks/build.rake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
33
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")
44

55
def dartsass_build_mapping
6-
Rails.application.config.dartsass.builds.map { |input, output|
6+
Rails.application.config.dartsass.builds.map { |input, output|
77
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
88
}.join(" ")
99
end
1010

1111
def dartsass_build_options
12-
"--load-path #{CSS_LOAD_PATH} --style=compressed --no-source-map"
12+
"#{load_paths} --style=compressed --no-source-map"
13+
end
14+
15+
def load_paths
16+
[CSS_LOAD_PATH].concat(Rails.application.config.dartsass.extra_load_paths)
17+
.map { |path| "--load-path #{path}" }
18+
.join(" ")
1319
end
1420

1521
def dartsass_compile_command

0 commit comments

Comments
 (0)