Skip to content
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

Add an option to add extra load paths #7

Closed
wants to merge 1 commit into from

Conversation

chipairon
Copy link
Contributor

This change allows to add extra load paths to the sass executable.

It is helpful when the an app has cutomized the entry points as well as when the entry points references other files that reside outside of the default CSS_LOAD_PATH.

That way, when files are changed under those extra directories, dartsass:watch will trigger a rebuild.

@mekhovov
Copy link

Would be lovely to merge this change. We have our assets in some non-standard (and in multiple Engines) folders.
It's super challenging to list all of them in dartsass.builds hash-like format.

@@ -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

@@ -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

@chipairon
Copy link
Contributor Author

Closed in favour of #11

@chipairon chipairon closed this Feb 18, 2022
@chipairon chipairon deleted the configurable-load-paths branch February 21, 2022 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants