Skip to content

Commit

Permalink
Add support for Tailwind CSS v4
Browse files Browse the repository at this point in the history
which doesn't need a config file or an input file anymore.

Closes #419
  • Loading branch information
flavorjones committed Oct 17, 2024
1 parent 3a3a0eb commit 6e828eb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## next / unreleased

* Add experimental support for Tailwind CSS v4. (#420) @flavorjones


## v3.0.0

### Notable changes
Expand Down
15 changes: 12 additions & 3 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
module Tailwindcss
module Commands
class << self
def tailwindcss_version
Tailwindcss::Ruby::VERSION
end

def compile_command(debug: false, **kwargs)
command = [
Tailwindcss::Ruby.executable(**kwargs),
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
"-c", Rails.root.join("config/tailwind.config.js").to_s,
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s
]

unless tailwindcss_version >= "4.0"
command += [
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
"-c", Rails.root.join("config/tailwind.config.js").to_s,
]
end

command << "--minify" unless (debug || rails_css_compressor?)

postcss_path = Rails.root.join("config/postcss.config.js")
Expand Down
28 changes: 27 additions & 1 deletion test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,33 @@ def setup
@executable = Tailwindcss::Ruby.executable
end

test ".compile_command" do
test ".compile_command with tailwindcss v3" do
Rails.stub(:root, File) do # Rails.root won't work in this test suite
Tailwindcss::Commands.stub(:tailwindcss_version, "3.4.13") do
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
assert_equal(executable, actual.first)
assert_includes(actual, "-i")
assert_includes(actual, "-c")
assert_includes(actual, "-o")
end
end
end

test ".compile_command with tailwindcss v4" do
Rails.stub(:root, File) do # Rails.root won't work in this test suite
Tailwindcss::Commands.stub(:tailwindcss_version, "4.0.0") do
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
assert_equal(executable, actual.first)
refute_includes(actual, "-i")
refute_includes(actual, "-c")
assert_includes(actual, "-o")
end
end
end

test ".compile_command debug flag" do
Rails.stub(:root, File) do # Rails.root won't work in this test suite
actual = Tailwindcss::Commands.compile_command
assert_kind_of(Array, actual)
Expand Down

0 comments on commit 6e828eb

Please sign in to comment.