Skip to content

Add an option to add extra load paths #7

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ 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/`.

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.
Copy link

@sedubois sedubois Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DHH was suggesting all vendor/assets/stylesheets folders should also be default, is there a way to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems a better approach #11


```
# config/initializers/dartsass.rb
Rails.application.config.dartsass.extra_load_paths = ["app/components"]
```

## Version

Expand Down
1 change: 1 addition & 0 deletions lib/dartsass/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module Dartsass
class Engine < ::Rails::Engine
config.dartsass = ActiveSupport::OrderedOptions.new
config.dartsass.builds = { "application.scss" => "application.css" }
config.dartsass.extra_load_paths = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also load all stylesheets by default

config.dartsass.paths = []

def default_paths
  Rails.application.config.assets[:paths].select do |path|
    path.to_s.match?(/stylesheets/)
  end
end

def load_paths
  use_paths = config.dartsass.paths || default_paths
  [CSS_LOAD_PATH].concat(use_paths).map { |path| "--load-path #{path}" }.join(" ") }
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think is a better approach and doesn't require extra configuration #11

end
end
10 changes: 8 additions & 2 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ 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"
"#{load_paths} --style=compressed --no-source-map"
end

def load_paths
[CSS_LOAD_PATH].concat(Rails.application.config.dartsass.extra_load_paths)
.map { |path| "--load-path #{path}" }
.join(" ")
end

def dartsass_compile_command
Expand Down