Skip to content

Commit 8196032

Browse files
authored
Merge pull request #2 from vocalvideo/multiple-stylesheets
Customize stylesheet entry points
2 parents de17ea6 + 9341a37 commit 8196032

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ When you're developing your application, you want to run Dart Sass in watch mode
2121

2222
The `dartsass:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Dart Sass output will be generated.
2323

24+
## Configuring Stylesheets
25+
26+
By default, only `app/assets/stylesheets/application.scss` will be built. If you'd like to change the path of this stylesheet, add additional entry points, or customize the name of the built file, use the `Rails.application.config.dartsass.stylesheets` configuration hash.
27+
28+
29+
```
30+
# config/initializers/dartsass.rb
31+
Rails.application.config.dartsass.stylesheets = {
32+
'app/index.sass' => 'app.css',
33+
'site.scss' => 'site.css'
34+
}
35+
```
36+
37+
The has 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/`.
38+
2439

2540
## Version
2641

lib/dartsass/engine.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
module Dartsass
44
class Engine < ::Rails::Engine
5+
config.dartsass = ActiveSupport::OrderedOptions.new
6+
config.dartsass.stylesheets = { 'application.scss' => 'appliction.css' }
57
end
68
end

lib/tasks/build.rake

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
DARTSASS_COMPILE_COMMAND = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass #{Rails.root.join("app/assets/stylesheets/application.scss")} #{Rails.root.join("app/assets/builds/application.scss")}"
1+
def dartsass_compile_command
2+
stylesheet_map = Rails.application.config.dartsass.stylesheets.map{|k, v| "#{Rails.root.join('app/assets/stylesheets', k)}:#{Rails.root.join('app/assets/builds', v)}"}.join(' ')
3+
"#{Pathname.new(__dir__).to_s}/../../exe/dartsass #{stylesheet_map}"
4+
end
25

36
namespace :dartsass do
47
desc "Build your Dart Sass CSS"
5-
task :build do
6-
system DARTSASS_COMPILE_COMMAND
8+
task build: :environment do
9+
system dartsass_compile_command
710
end
811

912
desc "Watch and build your Dart Sass CSS on file changes"
10-
task :watch do
11-
system "#{DARTSASS_COMPILE_COMMAND} -w"
13+
task watch: :environment do
14+
system "#{dartsass_compile_command} -w"
1215
end
1316
end
1417

0 commit comments

Comments
 (0)