diff --git a/README.md b/README.md index 10c08036..f7afe7a8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index fb90f4f6..bef42fd2 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -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 = [ diff --git a/test/lib/tailwindcss/commands_test.rb b/test/lib/tailwindcss/commands_test.rb index 3c7e5302..d09481a4 100644 --- a/test/lib/tailwindcss/commands_test.rb +++ b/test/lib/tailwindcss/commands_test.rb @@ -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