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 all commits
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak

### Building unminified assets

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]`.
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 non-blank value

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

### Live rebuild

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

command = [
Expand Down
26 changes: 26 additions & 0 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ def setup
end
end

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"] = ""
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
assert_includes(actual, "--minify")

actual = Tailwindcss::Commands.compile_command(debug: true)
assert_kind_of(Array, actual)
assert_includes(actual, "--minify")

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

actual = Tailwindcss::Commands.compile_command(debug: true)
assert_kind_of(Array, actual)
refute_includes(actual, "--minify")
end
ensure
ENV.delete('TAILWINDCSS_DEBUG')
end
end

test ".compile_command when Rails compression is on" do
Rails.stub(:root, File) do # Rails.root won't work in this test suite
Tailwindcss::Commands.stub(:rails_css_compressor?, true) do
Expand Down