Skip to content

Commit 6425cb7

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

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

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+
### Never minify 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

+10-1
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,21 @@ def watch_command(poll: false, **kwargs)
7474
end
7575

7676
def debug_option(rake_task_args_extras)
77-
rake_task_args_extras.include?("debug")
77+
rake_task_args_extras.include?("debug") || truthy_string_value(ENV['TAILWINDCSS_RAILS_NO_MINIFY'])
7878
end
7979

8080
def poll_option(rake_task_args_extras)
8181
rake_task_args_extras.include?("poll")
8282
end
83+
84+
def truthy_string_value(value)
85+
if !value.present? ||
86+
["f", "F", "false", "FALSE", "off", "OFF", "0"].include?(value)
87+
false
88+
else
89+
true
90+
end
91+
end
8392
end
8493
end
8594
end

test/lib/tailwindcss/commands_test.rb

+45
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,11 +97,48 @@ 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
95111
refute(Tailwindcss::Commands.poll_option([]))
96112
refute(Tailwindcss::Commands.poll_option(["debug"]))
97113
assert(Tailwindcss::Commands.poll_option(["poll"]))
98114
end
115+
116+
test ".truthy_string_value" do
117+
[
118+
nil,
119+
"",
120+
"F", "FALSE",
121+
"f", "false",
122+
"off", "OFF",
123+
"0",
124+
].each do |value|
125+
refute(
126+
Tailwindcss::Commands.truthy_string_value(value),
127+
"#{value.inspect} should be falsey",
128+
)
129+
end
130+
131+
[
132+
"T", "TRUE",
133+
"t", "true",
134+
"on", "ON",
135+
"1",
136+
"anything not falsey really",
137+
].each do |value|
138+
assert(
139+
Tailwindcss::Commands.truthy_string_value(value),
140+
"#{value.inspect} should be truthy",
141+
)
142+
end
143+
end
99144
end

0 commit comments

Comments
 (0)