Skip to content

Add app asset paths to load paths #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Rails.application.config.dartsass.builds = {

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/`.

## Importing assets from gems
`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.


## Version

Expand Down
10 changes: 7 additions & 3 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")

def dartsass_build_mapping
Rails.application.config.dartsass.builds.map { |input, output|
Rails.application.config.dartsass.builds.map { |input, output|
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
}.join(" ")
end

def dartsass_build_options
"--load-path #{CSS_LOAD_PATH} --style=compressed --no-source-map"
"--style=compressed --no-source-map"
end

def dartsass_load_paths
[ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).map { |path| "--load-path #{path}" }.join(" ")
end

def dartsass_compile_command
"#{EXEC_PATH} #{dartsass_build_options} #{dartsass_build_mapping}"
"#{EXEC_PATH} #{dartsass_build_options} #{dartsass_load_paths} #{dartsass_build_mapping}"
end

namespace :dartsass do
Expand Down