Skip to content

Commit a5ebd7f

Browse files
authored
Merge pull request #420 from rails/flavorjones-support-tailwind-4
Add experimental support for Tailwind CSS v4
2 parents 61cadc1 + 6e828eb commit a5ebd7f

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ jobs:
3737
fail-fast: false
3838
matrix:
3939
plat: ["ubuntu", "windows", "macos"]
40+
tailwind: ["--version=~>3.4.14", "--version=~>4.0.0.alpha.27"]
41+
env:
4042
runs-on: ${{matrix.plat}}-latest
43+
TAILWINDCSSOPTS: ${{ matrix.tailwind }}
4144
steps:
4245
- uses: actions/checkout@v4
4346
- uses: ruby/setup-ruby@v1

.github/workflows/upstream.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ jobs:
4242
matrix:
4343
plat: ["ubuntu"]
4444
ref: ["7-2-stable", "v8.0.0.beta1", "main"]
45+
tailwind: ["--version=~>3.4.14", "--version=~>4.0.0.alpha.27"]
4546
env:
4647
RAILSOPTS: --git=https://github.com/rails/rails --ref=${{ matrix.ref }}
48+
TAILWINDCSSOPTS: ${{ matrix.tailwind }}
4749
steps:
4850
- uses: actions/checkout@v4
4951
- uses: ruby/setup-ruby@v1

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
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

Lines changed: 12 additions & 3 deletions
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/integration/user_journey_test.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bundle remove rails --skip-install
2626
bundle add rails --skip-install ${RAILSOPTS:-}
2727

2828
# use the tailwindcss-rails under test
29-
bundle add tailwindcss-rails --path="../.."
29+
bundle add tailwindcss-rails --skip-install --path="../.."
30+
bundle add tailwindcss-ruby --skip-install ${TAILWINDCSSOPTS:-}
3031
bundle install
3132
bundle show --paths
3233
bundle binstubs --all
@@ -55,3 +56,9 @@ fi
5556
# TEST: presence of the generated file
5657
bin/rails generate scaffold post title:string body:text published:boolean
5758
grep -q "Show this post" app/views/posts/index.html.erb
59+
60+
# TEST: contents of the css file
61+
bin/rails tailwindcss:build[verbose]
62+
grep -q "py-2" app/assets/builds/tailwind.css
63+
64+
echo "OK"

test/lib/tailwindcss/commands_test.rb

Lines changed: 27 additions & 1 deletion
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)