Skip to content

Tailwindcss debug environment variable #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENV var should take precedence over command argument
  • Loading branch information
r-sierra authored and flavorjones committed Feb 25, 2025
commit 628b12615d0bcae572b241d32a03a83e6641bda7
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak
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]`.
- set an environment variable named `TAILWINDCSS_DEBUG` with a value of `true` or `1`
- set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value

If both values are set, the environment variable will take precedence over the rake task argument.

### Live rebuild

Expand Down
2 changes: 1 addition & 1 deletion lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Tailwindcss
module Commands
class << self
def compile_command(debug: false, **kwargs)
debug ||= ["true", "1"].include?(ENV["TAILWINDCSS_DEBUG"])
debug = ENV["TAILWINDCSS_DEBUG"].present? unless ENV["TAILWINDCSS_DEBUG"].nil?
rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)

command = [
Expand Down
14 changes: 6 additions & 8 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ def setup
test ".compile_command debug environment variable" do
begin
Rails.stub(:root, File) do # Rails.root won't work in this test suite
ENV["TAILWINDCSS_DEBUG"] = "0"
ENV["TAILWINDCSS_DEBUG"] = ""
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
assert_includes(actual, "--minify")

ENV["TAILWINDCSS_DEBUG"] = "1"
actual = Tailwindcss::Commands.compile_command
actual = Tailwindcss::Commands.compile_command(debug: true)
assert_kind_of(Array, actual)
refute_includes(actual, "--minify")
assert_includes(actual, "--minify")

ENV["TAILWINDCSS_DEBUG"] = "false"
ENV["TAILWINDCSS_DEBUG"] = "any non-blank value"
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
assert_includes(actual, "--minify")
refute_includes(actual, "--minify")

ENV["TAILWINDCSS_DEBUG"] = "true"
actual = Tailwindcss::Commands.compile_command
actual = Tailwindcss::Commands.compile_command(debug: true)
assert_kind_of(Array, actual)
refute_includes(actual, "--minify")
end
Expand Down