Skip to content

Commit 736ecb3

Browse files
author
David Heinemeier Hansson
committed
Only purge tailwind by default
Closes rails#5
1 parent a2abc42 commit 736ecb3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ If you need to customize what files are searched for class names, you need to re
3232
config.assets.css_compressor = Tailwindcss::Compressor.new(files_with_class_names: Rails.root.glob("app/somehere/**/*.*"))
3333
```
3434

35+
By default, the CSS purger will only operate on the tailwind css file included with this gem. If you want to use it more broadly:
36+
37+
```ruby
38+
config.assets.css_compressor = Tailwindcss::Compressor.new(only_purge: %w[ tailwind and_my_other_css_file ])
39+
```
3540

3641
## License
3742

lib/tailwindcss/compressor.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ def self.call(input)
1010
end
1111

1212
def initialize(options = {})
13-
@options = { files_with_class_names: Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb") }.merge(options).freeze
13+
@options = {
14+
files_with_class_names: Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb"),
15+
only_purge: %w[ tailwind ]
16+
}.merge(options).freeze
1417
end
1518

1619
def call(input)
17-
{ data: Tailwindcss::Purger.purge(input[:data], keeping_class_names_from_files: @options[:files_with_class_names]) }
20+
if input[:name].in?(@options[:only_purge])
21+
{ data: Tailwindcss::Purger.purge(input[:data], keeping_class_names_from_files: @options[:files_with_class_names]) }
22+
else
23+
input[:data]
24+
end
1825
end
1926
end

0 commit comments

Comments
 (0)