Skip to content

Commit 6e828eb

Browse files
committed
Add support for Tailwind CSS v4
which doesn't need a config file or an input file anymore. Closes #419
1 parent 3a3a0eb commit 6e828eb

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## next / unreleased
2+
3+
* Add experimental support for Tailwind CSS v4. (#420) @flavorjones
4+
5+
16
## v3.0.0
27

38
### Notable changes

lib/tailwindcss/commands.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
module Tailwindcss
44
module Commands
55
class << self
6+
def tailwindcss_version
7+
Tailwindcss::Ruby::VERSION
8+
end
9+
610
def compile_command(debug: false, **kwargs)
711
command = [
812
Tailwindcss::Ruby.executable(**kwargs),
9-
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
10-
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
11-
"-c", Rails.root.join("config/tailwind.config.js").to_s,
13+
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s
1214
]
1315

16+
unless tailwindcss_version >= "4.0"
17+
command += [
18+
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
19+
"-c", Rails.root.join("config/tailwind.config.js").to_s,
20+
]
21+
end
22+
1423
command << "--minify" unless (debug || rails_css_compressor?)
1524

1625
postcss_path = Rails.root.join("config/postcss.config.js")

test/lib/tailwindcss/commands_test.rb

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,33 @@ def setup
99
@executable = Tailwindcss::Ruby.executable
1010
end
1111

12-
test ".compile_command" do
12+
test ".compile_command with tailwindcss v3" do
13+
Rails.stub(:root, File) do # Rails.root won't work in this test suite
14+
Tailwindcss::Commands.stub(:tailwindcss_version, "3.4.13") do
15+
actual = Tailwindcss::Commands.compile_command
16+
assert_kind_of(Array, actual)
17+
assert_equal(executable, actual.first)
18+
assert_includes(actual, "-i")
19+
assert_includes(actual, "-c")
20+
assert_includes(actual, "-o")
21+
end
22+
end
23+
end
24+
25+
test ".compile_command with tailwindcss v4" do
26+
Rails.stub(:root, File) do # Rails.root won't work in this test suite
27+
Tailwindcss::Commands.stub(:tailwindcss_version, "4.0.0") do
28+
actual = Tailwindcss::Commands.compile_command
29+
assert_kind_of(Array, actual)
30+
assert_equal(executable, actual.first)
31+
refute_includes(actual, "-i")
32+
refute_includes(actual, "-c")
33+
assert_includes(actual, "-o")
34+
end
35+
end
36+
end
37+
38+
test ".compile_command debug flag" do
1339
Rails.stub(:root, File) do # Rails.root won't work in this test suite
1440
actual = Tailwindcss::Commands.compile_command
1541
assert_kind_of(Array, actual)

0 commit comments

Comments
 (0)