Skip to content

Commit 5ecd3a0

Browse files
Tailwindcss debug environment variable (#504)
* Add TAILWINDCSS_DEBUG environment variable * Update README * ENV var should take precedence over command argument * prefer Hash.key? to !Hash[].nil? --------- Co-authored-by: Mike Dalessio <[email protected]>
1 parent 5ff2c27 commit 5ecd3a0

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,12 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak
288288
289289
### Building unminified assets
290290
291-
If you want unminified assets, you can pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
291+
If you want unminified assets, you can:
292292
293+
- pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
294+
- set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value
295+
296+
If both values are set, the environment variable will take precedence over the rake task argument.
293297
294298
### Live rebuild
295299

Diff for: lib/tailwindcss/commands.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Tailwindcss
44
module Commands
55
class << self
66
def compile_command(debug: false, **kwargs)
7+
debug = ENV["TAILWINDCSS_DEBUG"].present? if ENV.key?("TAILWINDCSS_DEBUG")
78
rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
89

910
command = [

Diff for: test/lib/tailwindcss/commands_test.rb

+26
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ def setup
3333
end
3434
end
3535

36+
test ".compile_command debug environment variable" do
37+
begin
38+
Rails.stub(:root, File) do # Rails.root won't work in this test suite
39+
ENV["TAILWINDCSS_DEBUG"] = ""
40+
actual = Tailwindcss::Commands.compile_command
41+
assert_kind_of(Array, actual)
42+
assert_includes(actual, "--minify")
43+
44+
actual = Tailwindcss::Commands.compile_command(debug: true)
45+
assert_kind_of(Array, actual)
46+
assert_includes(actual, "--minify")
47+
48+
ENV["TAILWINDCSS_DEBUG"] = "any non-blank value"
49+
actual = Tailwindcss::Commands.compile_command
50+
assert_kind_of(Array, actual)
51+
refute_includes(actual, "--minify")
52+
53+
actual = Tailwindcss::Commands.compile_command(debug: true)
54+
assert_kind_of(Array, actual)
55+
refute_includes(actual, "--minify")
56+
end
57+
ensure
58+
ENV.delete('TAILWINDCSS_DEBUG')
59+
end
60+
end
61+
3662
test ".compile_command when Rails compression is on" do
3763
Rails.stub(:root, File) do # Rails.root won't work in this test suite
3864
Tailwindcss::Commands.stub(:rails_css_compressor?, true) do

0 commit comments

Comments
 (0)