Skip to content

Commit 3bd82c4

Browse files
committed
feat: allow users to specify "never minification"
1 parent d91c6ee commit 3bd82c4

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PATH
22
remote: .
33
specs:
44
tailwindcss-rails (2.0.22)
5+
activemodel (>= 6.0.0)
56
railties (>= 6.0.0)
67

78
GEM
@@ -33,6 +34,8 @@ GEM
3334
activejob (7.0.4.2)
3435
activesupport (= 7.0.4.2)
3536
globalid (>= 0.3.6)
37+
activemodel (7.0.4.2)
38+
activesupport (= 7.0.4.2)
3639
activesupport (7.0.4.2)
3740
concurrent-ruby (~> 1.0, >= 1.0.2)
3841
i18n (>= 1.6, < 2)

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ If you want unminified assets, you can pass a `debug` argument to the rake task,
5555
Note that you can combine task options, e.g. `rails tailwindcss:watch[debug,poll]`.
5656

5757

58+
### Always avoid minification assets
59+
60+
If you _always_ want unminified assets, you can set the environment variable `TAILWINDCSS_RAILS_NO_MINIFY` to something that [looks truthy](https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html) (hint: "t" or "1" will work).
61+
62+
5863
### Custom inputs or outputs
5964

6065
If you need to use a custom input or output file, you can run `bundle exec tailwindcss` to access the platform-specific executable, and give it your own build options.

lib/tailwindcss/commands.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative "upstream"
2+
require "active_model/type"
23

34
module Tailwindcss
45
module Commands
@@ -74,12 +75,16 @@ def watch_command(poll: false, **kwargs)
7475
end
7576

7677
def debug_option(rake_task_args_extras)
77-
rake_task_args_extras.include?("debug")
78+
rake_task_args_extras.include?("debug") || truthy_string_value(ENV['TAILWINDCSS_RAILS_NO_MINIFY'])
7879
end
7980

8081
def poll_option(rake_task_args_extras)
8182
rake_task_args_extras.include?("poll")
8283
end
84+
85+
def truthy_string_value(value)
86+
ActiveModel::Type::Boolean.new.cast(value)
87+
end
8388
end
8489
end
8590
end

tailwindcss-rails.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
1919
spec.executables << "tailwindcss"
2020

2121
spec.add_dependency "railties", ">= 6.0.0"
22+
spec.add_dependency "activemodel", ">= 6.0.0"
2223
end

test/lib/tailwindcss/commands_test.rb

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def mock_exe_directory(platform)
1818
end
1919
end
2020

21+
def with_env(env)
22+
before = ENV.to_h.dup
23+
env.each { |k, v| ENV[k] = v }
24+
yield
25+
ensure
26+
ENV.replace(before)
27+
end
28+
2129
test ".executable returns the absolute path to the binary" do
2230
mock_exe_directory("sparc-solaris2.8") do |dir, executable|
2331
expected = File.expand_path(File.join(dir, "sparc-solaris2.8", "tailwindcss"))
@@ -89,6 +97,14 @@ def mock_exe_directory(platform)
8997
refute(Tailwindcss::Commands.debug_option([]))
9098
assert(Tailwindcss::Commands.debug_option(["debug"]))
9199
refute(Tailwindcss::Commands.debug_option(["poll"]))
100+
101+
with_env({"TAILWINDCSS_RAILS_NO_MINIFY" => "f"}) do
102+
refute(Tailwindcss::Commands.debug_option([]))
103+
end
104+
105+
with_env({"TAILWINDCSS_RAILS_NO_MINIFY" => "t"}) do
106+
assert(Tailwindcss::Commands.debug_option([]))
107+
end
92108
end
93109

94110
test ".poll_option" do

0 commit comments

Comments
 (0)