Skip to content

Commit 3d2e066

Browse files
committed
feat: generate unminified assets with debug task param
Suggested by #163
1 parent baa5e50 commit 3d2e066

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
## Unreleased
33

4-
* Correctly handle paths with embedded spaces. [#184](https://github.com/rails/tailwindcss-rails/issues/184)
4+
* Correctly handle paths with embedded spaces. [#184](https://github.com/rails/tailwindcss-rails/issues/184) by [@flavorjones](https://github.com/flavorjones)
5+
* Rake tasks accept a `debug` argument to generate unminified assets, e.g. `tailwindcss:build[debug]`. [#198](https://github.com/rails/tailwindcss-rails/pull/198) by [@flavorjones](https://github.com/flavorjones)
56

67

78
## v2.0.12 / 2022-08-10

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ You can customize the Tailwind build through the `config/tailwind.config.js` fil
88

99
The installer will create your Tailwind input file in `app/assets/stylesheets/application.tailwind.css`. This is where you import the plugins you want to use, and where you can setup your custom `@apply` rules. When you run `rails tailwindcss:build`, this input file will be used to generate the output in `app/assets/builds/tailwind.css`. That's the output CSS that you'll include in your app (the installer automatically configures this, alongside the Inter font as well).
1010

11-
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.
11+
**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.
1212

13-
When you're developing your application, you want to run Tailwind in watch mode, so changes are automatically reflected in the generated CSS output. You can do this either by running `rails tailwindcss:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to starts both the Tailwind watch process and the rails server in development mode. If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.
13+
**When you're developing your application**, you want to run Tailwind in watch mode, so changes are automatically reflected in the generated CSS output. You can do this either by running `rails tailwindcss:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to starts both the Tailwind watch process and the rails server in development mode. If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.
14+
15+
**If you want unminified assets**, you can pass the `debug` parameter to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
1416

1517

1618
## Installation

lib/tailwindcss/commands.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ def executable(
5555
exe_path
5656
end
5757

58-
def compile_command(**kwargs)
58+
def compile_command(debug: false, **kwargs)
5959
[
6060
executable(**kwargs),
6161
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
6262
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
6363
"-c", Rails.root.join("config/tailwind.config.js").to_s,
64-
"--minify",
65-
]
64+
].tap do |command|
65+
command << "--minify" unless debug
66+
end
6667
end
6768

6869
def watch_command(**kwargs)

lib/tasks/build.rake

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
namespace :tailwindcss do
22
desc "Build your Tailwind CSS"
3-
task :build do
4-
command = Tailwindcss::Commands.compile_command
3+
task :build do |_, args|
4+
debug = args.extras.include?("debug")
5+
command = Tailwindcss::Commands.compile_command(debug: debug)
56
puts command.inspect
67
system(*command, exception: true)
78
end
89

910
desc "Watch and build your Tailwind CSS on file changes"
10-
task :watch do
11-
command = Tailwindcss::Commands.watch_command
11+
task :watch do |_, args|
12+
debug = args.extras.include?("debug")
13+
command = Tailwindcss::Commands.watch_command(debug: debug)
1214
puts command.inspect
1315
system(*command)
1416
end

test/lib/tailwindcss/commands_test.rb

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def mock_exe_directory(platform)
4848
actual = Tailwindcss::Commands.compile_command(exe_path: dir)
4949
assert_kind_of(Array, actual)
5050
assert_equal(executable, actual.first)
51+
assert_includes(actual, "--minify")
52+
53+
actual = Tailwindcss::Commands.compile_command(exe_path: dir, debug: true)
54+
assert_kind_of(Array, actual)
55+
assert_equal(executable, actual.first)
56+
refute_includes(actual, "--minify")
5157
end
5258
end
5359
end
@@ -59,6 +65,13 @@ def mock_exe_directory(platform)
5965
assert_kind_of(Array, actual)
6066
assert_equal(executable, actual.first)
6167
assert_includes(actual, "-w")
68+
assert_includes(actual, "--minify")
69+
70+
actual = Tailwindcss::Commands.watch_command(exe_path: dir, debug: true)
71+
assert_kind_of(Array, actual)
72+
assert_equal(executable, actual.first)
73+
assert_includes(actual, "-w")
74+
refute_includes(actual, "--minify")
6275
end
6376
end
6477
end

0 commit comments

Comments
 (0)