From d50dae43c67a35ebf206f2085361094f761b2564 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Wed, 11 Jun 2025 18:00:46 +0300 Subject: [PATCH 01/10] Implement Engines Support --- Gemfile.lock | 2 +- README.md | 77 +++++----- lib/tailwindcss-rails.rb | 1 + lib/tailwindcss/engine.rb | 4 + lib/tailwindcss/engines.rb | 23 +++ test/lib/tailwindcss/engine_test.rb | 38 +++++ test/lib/tailwindcss/engines_test.rb | 208 +++++++++++++++++++++++++++ 7 files changed, 307 insertions(+), 46 deletions(-) create mode 100644 lib/tailwindcss/engines.rb create mode 100644 test/lib/tailwindcss/engine_test.rb create mode 100644 test/lib/tailwindcss/engines_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 9b0500db..3a61813b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - tailwindcss-rails (4.2.2) + tailwindcss-rails (4.2.3) railties (>= 7.0.0) tailwindcss-ruby (~> 4.0) diff --git a/README.md b/README.md index 158b1750..b4c9a786 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,10 @@ * [Live rebuild](#live-rebuild) * [Using Tailwind plugins](#using-tailwind-plugins) * [Using with PostCSS](#using-with-postcss) + * [Rails Engines support](#rails-engines-support) * [Custom inputs or outputs](#custom-inputs-or-outputs) - [Troubleshooting](#troubleshooting) + * [The `watch` command is hanging](#the-watch-command-is-hanging) * [Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin](#lost-keystrokes-or-hanging-when-using-terminal-based-debugging-tools-eg-irb-pry-rubydebugetc-with-the-puma-plugin) * [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely) * [Conflict with sassc-rails](#conflict-with-sassc-rails) @@ -43,12 +45,11 @@ With Rails 7 you can generate a new application preconfigured with Tailwind CSS This gem depends on the `tailwindcss-ruby` gem to install a working Tailwind CLI executable. - ### Choosing a specific version of `tailwindcss` The `tailwindcss-ruby` gem is declared as a floating dependency of this gem, so by default you will get the most recent stable version. However, you can select a specific version of Tailwind CSS by pinning that gem to the analogous version in your application's `Gemfile`. For example, -``` ruby +```ruby gem "tailwindcss-rails" # pin to tailwindcss version 3.4.13 @@ -59,7 +60,6 @@ gem "tailwindcss-ruby", "3.4.13" You can also use a local (npm-based) installation if you prefer, please go to https://github.com/flavorjones/tailwindcss-ruby for more information. - ## Upgrading your application from Tailwind v3 to v4 v4.x of this gem has been updated to work with Tailwind v4, including providing some help with upgrading your application. @@ -72,27 +72,25 @@ This gem will help with some of the mechanics of the upgrade: - update some local project files to meet some Tailwind CSS v4 conventions, - attempt to run the [upstream v4 upgrade tool](https://tailwindcss.com/docs/upgrade-guide#using-the-upgrade-tool). - ### You don't _have_ to upgrade Keep in mind that you don't _need_ to upgrade. You can stay on Tailwind CSS v3 for the foreseeable future if you prefer not to migrate now, or if your migration runs into problems. If you don't want to upgrade, then pin your application to v3.3.1 of this gem: -``` ruby +```ruby # Gemfile gem "tailwindcss-rails", "~> 3.3.1" # which transitively pins tailwindcss-ruby to v3 ``` If you're on an earlier version of this gem, `<= 3.3.0`, then make sure you're pinning the version of **both** `tailwindcss-rails` and `tailwindcss-ruby`: -``` ruby +```ruby # Gemfile gem "tailwindcss-rails", "~> 3.3" gem "tailwindcss-ruby", "~> 3.4" # only necessary with tailwindcss-rails <= 3.3.0 ``` - ### Upgrade steps > [!WARNING] @@ -101,8 +99,8 @@ gem "tailwindcss-ruby", "~> 3.4" # only necessary with tailwindcss-rails <= 3.3. First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4. ```html -# Gemfile -gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4 +# Gemfile gem "tailwindcss-rails", "~> 4.0" # which transitively pins +tailwindcss-ruby to v4 ``` **Update** path references to any existing css files imported in `app/assets/stylesheets/application.tailwind.css` so that they will resolve when the file is moved to `app/assets/tailwind/application.css`. @@ -114,7 +112,7 @@ gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to If you want to migrate CSS class names for v4 (this is an optional step!), jump to [Updating CSS class names for v4](#updating-css-class-names-for-v4) before continuing. -Then, run `bin/rails tailwindcss:upgrade`. Among other things, this will try to run the official Tailwind upgrade utility. It requires `npx` in order to run, but it's a one-time operation and is *highly recommended* for a successful upgrade. +Then, run `bin/rails tailwindcss:upgrade`. Among other things, this will try to run the official Tailwind upgrade utility. It requires `npx` in order to run, but it's a one-time operation and is _highly recommended_ for a successful upgrade.
Here's a detailed list of what the upgrade task does. @@ -131,7 +129,7 @@ Then, run `bin/rails tailwindcss:upgrade`. Among other things, this will try to
Here's what that upgrade looks like on a vanilla Rails app. -``` sh +```sh $ bin/rails tailwindcss:upgrade apply /path/to/tailwindcss-rails/lib/install/upgrade_tailwindcss.rb Removing references to 'defaultTheme' from /home/user/myapp/config/tailwind.config.js @@ -166,12 +164,11 @@ $ bin/rails tailwindcss:upgrade Done in 56ms run bundle install --quiet ``` -
+
If this doesn't succeed, it's likely that you've customized your Tailwind configuration and you'll need to do some work to make sure your application upgrades. Please read the [official upgrade guide](https://tailwindcss.com/docs/upgrade-guide) and try following the additional steps in [Updating CSS class names for v4](#updating-css-class-names-for-v4). - ### Troubleshooting a v4 upgrade You may want to check out [TailwindCSS v4 - upgrade experience report · rails/tailwindcss-rails · Discussion #450](https://github.com/rails/tailwindcss-rails/discussions/450) if you're having trouble upgrading. @@ -182,7 +179,6 @@ We know there are some cases we haven't addressed with the upgrade task: We'll try to improve the upgrade process over time, but for now you may need to do some manual work to upgrade. - ### Updating CSS class names for v4 > [!NOTE] @@ -208,9 +204,9 @@ With some additional manual work the upstream upgrade tool will update your appl "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/container-queries": "^0.1.1", "@tailwindcss/forms": "^0.5.10", - "@tailwindcss/typography": "^0.5.16" + "@tailwindcss/typography": "^0.5.16", // And so on... - } + }, } ``` @@ -280,12 +276,10 @@ This gem also generates a `Procfile.dev` file which will run both the rails serv The `tailwindcss:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Tailwind output will be generated. - ### Building for testing The `tailwindcss:build` task is automatically attached to the `test:prepare` Rake task. This task runs before test commands. If you run `bin/rails test` in your CI environment, your Tailwind output will be generated before tests run. - ### Building unminified assets If you want unminified assets, you can: @@ -303,7 +297,6 @@ While you're developing your application, you want to run Tailwind in "watch" mo - or run `rails tailwindcss:watch` as a separate process, - or run `bin/dev` which uses [Foreman](https://github.com/ddollar/foreman) - #### Puma plugin This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` configuration: @@ -314,7 +307,6 @@ plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development" and then running `rails server` (or just `puma`) will run the Tailwind watch process in the background. - #### Run `rails tailwindcss:watch` This is a flexible command, which can be run with a few different options. @@ -331,38 +323,35 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container, If you are running `rails tailwindcss:watch` in a docker container without a tty, pass the `always` argument to the task to instruct tailwindcss to keep the watcher alive even when `stdin` is closed: `rails tailwindcss:watch[always]`. If you use `bin/dev` then you should modify your `Procfile.dev`. - #### Foreman Running `bin/dev` invokes Foreman to start both the Tailwind watch process and the rails server in development mode based on your `Procfile.dev` file. - ### Using Tailwind plugins If you want to use Tailwind plugins, they can be installed using `package.json`. Using Yarn: -``` sh +```sh [ ! -f package.json ] && yarn init yarn add daisyui # example ``` Using npm: -``` sh +```sh npm init npm add daisyui # example ``` Than use `@plugin` annotation in `app/assets/tailwind/application.css`: -``` css +```css @import "tailwindcss"; @plugin "daisyui"; ``` - ### Using with PostCSS If you want to use PostCSS as a preprocessor, create a custom `postcss.config.js` in your project root directory, and that file will be loaded by Tailwind automatically. @@ -374,8 +363,8 @@ For example, to enable nesting: export default { plugins: { "@tailwindcss/postcss": {}, - } -} + }, +}; ``` ⚠ Note that PostCSS is a JavaScript tool with its own prerequisites! By default `tailwindcss-rails` does not require any JavaScript tooling, so in order to use PostCSS, a `package.json` with dependencies for your plugins and a package manager like `yarn` or `npm` is required, for example: @@ -395,12 +384,14 @@ export default { Then you can use yarn or npm to install the dependencies. +### Rails Engines support + +If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//application.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../../assets/builds/tailwind/"` to your `app/assets/tailwind/application.css` file. ### Custom inputs or outputs 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. - ## Troubleshooting When having trouble with `tailwindcss:build` or `tailwindcss:watch`, the first thing you should do is collect some diagnostic information by setting the "verbose" flag, which will emit: @@ -410,7 +401,7 @@ When having trouble with `tailwindcss:build` or `tailwindcss:watch`, the first t Here's what that looks like: -``` sh +```sh $ bin/rails tailwindcss:build[verbose] Running: /path/to/tailwindcss-ruby-4.0.17-x86_64-linux-gnu/exe/x86_64-linux-gnu/tailwindcss -i /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/tailwind/application.css -o /home/flavorjones/code/oss/tailwindcss-rails/My Workspace/test-install/app/assets/builds/tailwind.css --minify @@ -432,34 +423,28 @@ There is a [known issue](https://github.com/tailwindlabs/tailwindcss/issues/1724 Please try uninstalling `watchman` and try running the watch task again. - ### Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin We've addressed the issue and you can avoid the problem by upgrading `tailwindcss-rails` to [v2.4.1](https://github.com/rails/tailwindcss-rails/releases/tag/v2.4.1) or later versions. - ### Running in a docker container exits prematurely 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. If you are running `rails tailwindcss:watch` in a docker container without a tty, pass the `always` argument to the task to instruct tailwindcss to keep the watcher alive even when `stdin` is closed: `rails tailwindcss:watch[always]`. If you use `bin/dev` then you should modify your `Procfile.dev`. - ### Conflict with sassc-rails Tailwind uses modern CSS features that are not recognized by the `sassc-rails` extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like `SassC::SyntaxError`, you must remove that gem from your Gemfile. - ### Class names must be spelled out For Tailwind to work, your class names need to be spelled out. If you need to make sure Tailwind generates class names that don't exist in your content files or that are programmatically composed, use the [safelist option](https://tailwindcss.com/docs/content-configuration#safelisting-classes). - ### `ERROR: Cannot find the tailwindcss executable` for supported platform See https://github.com/flavorjones/tailwindcss-ruby for help. - ### Using asset-pipeline assets In Rails, you want to use [assets from the asset pipeline to get fingerprinting](https://guides.rubyonrails.org/asset_pipeline.html#fingerprinting-versioning-with-digest-based-urls). However, Tailwind isn't aware of those assets. @@ -468,20 +453,22 @@ To use assets from the pipeline, use `url(image.svg)`. [Since Sprockets v3.3.0]( ```js module.exports = { - theme: { - extend: { - backgroundImage: { - 'image': "url('image.svg')" - } - } - } -} + theme: { + extend: { + backgroundImage: { + image: "url('image.svg')", + }, + }, + }, +}; ``` The inline version also works: ```html -
Has the image as it's background
+
+ Has the image as it's background +
``` ## License diff --git a/lib/tailwindcss-rails.rb b/lib/tailwindcss-rails.rb index 2b86ff1c..bdfb592d 100644 --- a/lib/tailwindcss-rails.rb +++ b/lib/tailwindcss-rails.rb @@ -2,5 +2,6 @@ module Tailwindcss end require_relative "tailwindcss/version" +require_relative "tailwindcss/engines" require_relative "tailwindcss/engine" require_relative "tailwindcss/commands" diff --git a/lib/tailwindcss/engine.rb b/lib/tailwindcss/engine.rb index 7b88c5f1..001004f8 100644 --- a/lib/tailwindcss/engine.rb +++ b/lib/tailwindcss/engine.rb @@ -15,5 +15,9 @@ class Engine < ::Rails::Engine config.app_generators do |g| g.template_engine :tailwindcss end + + config.after_initialize do + Tailwindcss::Engines.bundle + end end end diff --git a/lib/tailwindcss/engines.rb b/lib/tailwindcss/engines.rb new file mode 100644 index 00000000..a0280876 --- /dev/null +++ b/lib/tailwindcss/engines.rb @@ -0,0 +1,23 @@ +module Tailwindcss + module Engines + class << self + def bundle + FileUtils.mkdir_p(Rails.root.join("app/assets/builds/tailwind")) + Rails::Engine.subclasses.select do |engine| + engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css").exist? + end.each do |engine| + file_path = Rails.root.join("app/assets/builds/tailwind/#{engine.engine_name}.css") + FileUtils.rm(file_path) if File.exist?(file_path) + template = <<~TEMPLATE + /* DO NOT MODIFY THIS FILE, it was auto-generated by tailwindcss-rails */ + + @import "#{engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css")}"; + TEMPLATE + File.open(file_path, 'w') do |file| + file.puts template + end + end + end + end + end +end diff --git a/test/lib/tailwindcss/engine_test.rb b/test/lib/tailwindcss/engine_test.rb new file mode 100644 index 00000000..46e4f0cd --- /dev/null +++ b/test/lib/tailwindcss/engine_test.rb @@ -0,0 +1,38 @@ +require "test_helper" +require "minitest/mock" + +class Tailwindcss::EngineTest < ActiveSupport::TestCase + def setup + super + # Store original Rails state + @original_rails_root = Rails.root + @original_application = Rails.application + end + + def teardown + super + # Restore original Rails state + Rails.application = @original_application if @original_application + end + + test "after_initialize calls Tailwindcss::Engines.bundle" do + called = false + + # Replace bundle method with our spy + Tailwindcss::Engines.stub(:bundle, ->{ called = true }) do + # Execute the after_initialize block + Rails.stub(:root, File) do + engine_file = File.join(File.dirname(__FILE__), "../../../lib/tailwindcss/engine.rb") + engine_code = File.read(engine_file) + + # Verify that the after_initialize block calls Engines.bundle + assert_match(/config\.after_initialize do.*?Tailwindcss::Engines\.bundle.*?end/m, engine_code, + "Expected after_initialize block to call Tailwindcss::Engines.bundle") + + # Call bundle to verify our spy works + Tailwindcss::Engines.bundle + assert called, "Expected Tailwindcss::Engines.bundle to be called" + end + end + end +end \ No newline at end of file diff --git a/test/lib/tailwindcss/engines_test.rb b/test/lib/tailwindcss/engines_test.rb new file mode 100644 index 00000000..dacbd176 --- /dev/null +++ b/test/lib/tailwindcss/engines_test.rb @@ -0,0 +1,208 @@ +require "test_helper" + +class Tailwindcss::EnginesTest < ActiveSupport::TestCase + def setup + super + # Store original Rails state + @original_rails_root = Rails.root + @original_application = Rails.application + @test_app_root = Pathname.new(TAILWINDCSS_TEST_APP_ROOT) + + # Set up directories + @builds_dir = @test_app_root.join("app/assets/builds/tailwind") + FileUtils.rm_rf(@builds_dir) if Dir.exist?(@builds_dir) + + # Save original subclasses to restore later + @original_subclasses = Rails::Engine.subclasses.dup + end + + def teardown + super + # Restore original state + Rails.application = @original_application if @original_application + + # If we've modified the Rails::Engine subclasses, restore them + if @original_subclasses + Rails::Engine.instance_variable_set(:@subclasses, @original_subclasses) + end + + # Clean up test directory + FileUtils.rm_rf(@builds_dir) if Dir.exist?(@builds_dir) + end + + test "bundle creates the builds directory" do + # Store the original Rails application for restoration later + original_app = Rails.application + + Dir.mktmpdir do |tmpdir| + @tmpdir = tmpdir + tmpdir_path = Pathname.new(tmpdir) + builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + + Rails.stub(:root, tmpdir_path) do + # Execute the bundle method + Tailwindcss::Engines.bundle + + # Assert that the directory was created + assert Dir.exist?(builds_dir), "Expected directory #{builds_dir} to be created" + end + end + + # Restore the original Rails application + Rails.application = original_app + end + + test "bundle generates CSS files for engine's tailwind assets" do + # Store the original Rails application and engine subclasses + original_app = Rails.application + original_subclasses = Rails::Engine.subclasses.dup + + Dir.mktmpdir do |tmpdir| + @tmpdir = tmpdir + tmpdir_path = Pathname.new(tmpdir) + builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + + Rails.stub(:root, tmpdir_path) do + # Create a mock engine with tailwind assets + setup_mock_engine("mock_engine", tmpdir_path) + + # Execute the bundle method + Tailwindcss::Engines.bundle + + # Assert that the CSS file was generated + css_file_path = builds_dir.join("mock_engine.css") + assert File.exist?(css_file_path), "Expected file #{css_file_path} to be created" + + # Check content of the generated file + content = File.read(css_file_path) + assert_match(/DO NOT MODIFY THIS FILE/, content) + assert_match(/@import ".*\/app\/assets\/tailwind\/mock_engine\/application.css"/, content) + end + end + + # Restore the original Rails application and engine subclasses + Rails.application = original_app + Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) + end + + test "bundle removes existing files before generating new ones" do + # Store the original Rails application and engine subclasses + original_app = Rails.application + original_subclasses = Rails::Engine.subclasses.dup + + Dir.mktmpdir do |tmpdir| + @tmpdir = tmpdir + tmpdir_path = Pathname.new(tmpdir) + builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + + Rails.stub(:root, tmpdir_path) do + # Create a mock engine with tailwind assets + setup_mock_engine("mock_engine", tmpdir_path) + + # Create an existing file that should be replaced + FileUtils.mkdir_p(builds_dir) + css_file_path = builds_dir.join("mock_engine.css") + File.write(css_file_path, "OLD CONTENT") + + # Execute the bundle method + Tailwindcss::Engines.bundle + + # Assert that the old content was removed + content = File.read(css_file_path) + assert_no_match(/OLD CONTENT/, content) + assert_match(/DO NOT MODIFY THIS FILE/, content) + end + end + + # Restore the original Rails application and engine subclasses + Rails.application = original_app + Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) + end + + test "bundle only processes engines with tailwind assets" do + # Store the original Rails application and engine subclasses + original_app = Rails.application + original_subclasses = Rails::Engine.subclasses.dup + + Dir.mktmpdir do |tmpdir| + @tmpdir = tmpdir + tmpdir_path = Pathname.new(tmpdir) + builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + + Rails.stub(:root, tmpdir_path) do + # Create a mock engine with tailwind assets + setup_mock_engine("engine_with_assets", tmpdir_path) + + # Create a mock engine without tailwind assets + root_path = tmpdir_path + mock_engine_without_assets = Class.new(Rails::Engine) do + define_singleton_method(:engine_name) { "engine_without_assets" } + define_singleton_method(:root) { root_path } + end + Rails::Engine.instance_variable_set(:@subclasses, Rails::Engine.subclasses + [mock_engine_without_assets]) + + # Execute the bundle method + Tailwindcss::Engines.bundle + + # Assert that only the engine with assets has a CSS file generated + assert File.exist?(builds_dir.join("engine_with_assets.css")), "Expected CSS file for engine with assets" + refute File.exist?(builds_dir.join("engine_without_assets.css")), "Expected no CSS file for engine without assets" + end + end + + # Restore the original Rails application and engine subclasses + Rails.application = original_app + Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) + end + + test "bundle handles multiple engines" do + # Store the original Rails application and engine subclasses + original_app = Rails.application + original_subclasses = Rails::Engine.subclasses.dup + + Dir.mktmpdir do |tmpdir| + @tmpdir = tmpdir + tmpdir_path = Pathname.new(tmpdir) + builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + + Rails.stub(:root, tmpdir_path) do + # Create multiple mock engines with tailwind assets + setup_mock_engine("engine1", tmpdir_path) + setup_mock_engine("engine2", tmpdir_path) + + # Execute the bundle method + Tailwindcss::Engines.bundle + + # Assert that CSS files were generated for both engines + assert File.exist?(builds_dir.join("engine1.css")), "Expected CSS file for engine1" + assert File.exist?(builds_dir.join("engine2.css")), "Expected CSS file for engine2" + end + end + + # Restore the original Rails application and engine subclasses + Rails.application = original_app + Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) + end + + private + + def setup_mock_engine(name, root_path) + # Create a mock Rails engine with captured local variables + engine_name = name + path = root_path + mock_engine = Class.new(Rails::Engine) do + define_singleton_method(:engine_name) { engine_name } + define_singleton_method(:root) { path } + end + + # Create the required tailwind asset file for the mock engine + tailwind_dir = root_path.join("app/assets/tailwind/#{name}") + FileUtils.mkdir_p(tailwind_dir) + File.write(tailwind_dir.join("application.css"), "/* Test CSS */") + + # Add the mock engine to Rails::Engine.subclasses + Rails::Engine.instance_variable_set(:@subclasses, Rails::Engine.subclasses + [mock_engine]) + + mock_engine + end +end \ No newline at end of file From 97658955d41b5586252b7e8d95f9c14ba624f7d6 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Wed, 11 Jun 2025 23:34:06 +0300 Subject: [PATCH 02/10] Correction in README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4c9a786..c9630efc 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,9 @@ gem "tailwindcss-ruby", "~> 3.4" # only necessary with tailwindcss-rails <= 3.3. First, update to `tailwindcss-rails` v4.0.0 or higher. This will also ensure you're transitively depending on `tailwindcss-ruby` v4. -```html -# Gemfile gem "tailwindcss-rails", "~> 4.0" # which transitively pins -tailwindcss-ruby to v4 +```ruby +# Gemfile +gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4 ``` **Update** path references to any existing css files imported in `app/assets/stylesheets/application.tailwind.css` so that they will resolve when the file is moved to `app/assets/tailwind/application.css`. From 430e61109dc9df49d6c34c807b02faedc0dc427e Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Wed, 11 Jun 2025 23:37:26 +0300 Subject: [PATCH 03/10] Remove engine test --- test/lib/tailwindcss/engine_test.rb | 38 ----------------------------- 1 file changed, 38 deletions(-) delete mode 100644 test/lib/tailwindcss/engine_test.rb diff --git a/test/lib/tailwindcss/engine_test.rb b/test/lib/tailwindcss/engine_test.rb deleted file mode 100644 index 46e4f0cd..00000000 --- a/test/lib/tailwindcss/engine_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "test_helper" -require "minitest/mock" - -class Tailwindcss::EngineTest < ActiveSupport::TestCase - def setup - super - # Store original Rails state - @original_rails_root = Rails.root - @original_application = Rails.application - end - - def teardown - super - # Restore original Rails state - Rails.application = @original_application if @original_application - end - - test "after_initialize calls Tailwindcss::Engines.bundle" do - called = false - - # Replace bundle method with our spy - Tailwindcss::Engines.stub(:bundle, ->{ called = true }) do - # Execute the after_initialize block - Rails.stub(:root, File) do - engine_file = File.join(File.dirname(__FILE__), "../../../lib/tailwindcss/engine.rb") - engine_code = File.read(engine_file) - - # Verify that the after_initialize block calls Engines.bundle - assert_match(/config\.after_initialize do.*?Tailwindcss::Engines\.bundle.*?end/m, engine_code, - "Expected after_initialize block to call Tailwindcss::Engines.bundle") - - # Call bundle to verify our spy works - Tailwindcss::Engines.bundle - assert called, "Expected Tailwindcss::Engines.bundle to be called" - end - end - end -end \ No newline at end of file From a253d6745e2951e689db87595a7b3a9355c700e2 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Wed, 11 Jun 2025 23:47:28 +0300 Subject: [PATCH 04/10] Rename to engine.css --- README.md | 5 ++++- lib/tailwindcss/engines.rb | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c9630efc..92af0447 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,10 @@ Then you can use yarn or npm to install the dependencies. ### Rails Engines support -If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//application.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../../assets/builds/tailwind/"` to your `app/assets/tailwind/application.css` file. +If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../../assets/builds/tailwind/"` to your `app/assets/tailwind/application.css` file. + +> [!IMPORTANT] +> Only imported in `app/assets/tailwind/application.css` engine CSS files will be included in the build. By default, no engine CSS files are imported. This give you flexibility on which engine CSS files you want to include in your build. ### Custom inputs or outputs diff --git a/lib/tailwindcss/engines.rb b/lib/tailwindcss/engines.rb index a0280876..d1d6bf63 100644 --- a/lib/tailwindcss/engines.rb +++ b/lib/tailwindcss/engines.rb @@ -4,14 +4,14 @@ class << self def bundle FileUtils.mkdir_p(Rails.root.join("app/assets/builds/tailwind")) Rails::Engine.subclasses.select do |engine| - engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css").exist? + engine.root.join("app/assets/tailwind/#{engine.engine_name}/engine.css").exist? end.each do |engine| file_path = Rails.root.join("app/assets/builds/tailwind/#{engine.engine_name}.css") FileUtils.rm(file_path) if File.exist?(file_path) template = <<~TEMPLATE /* DO NOT MODIFY THIS FILE, it was auto-generated by tailwindcss-rails */ - @import "#{engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css")}"; + @import "#{engine.root.join("app/assets/tailwind/#{engine.engine_name}/engine.css")}"; TEMPLATE File.open(file_path, 'w') do |file| file.puts template From f3772d6bf368d74d19df4ec10870767f148603d0 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Thu, 12 Jun 2025 00:00:29 +0300 Subject: [PATCH 05/10] Initial test cleanup --- test/lib/tailwindcss/engines_test.rb | 134 +++++---------------------- 1 file changed, 22 insertions(+), 112 deletions(-) diff --git a/test/lib/tailwindcss/engines_test.rb b/test/lib/tailwindcss/engines_test.rb index dacbd176..9209e54b 100644 --- a/test/lib/tailwindcss/engines_test.rb +++ b/test/lib/tailwindcss/engines_test.rb @@ -1,208 +1,118 @@ require "test_helper" class Tailwindcss::EnginesTest < ActiveSupport::TestCase - def setup - super - # Store original Rails state - @original_rails_root = Rails.root - @original_application = Rails.application - @test_app_root = Pathname.new(TAILWINDCSS_TEST_APP_ROOT) - - # Set up directories - @builds_dir = @test_app_root.join("app/assets/builds/tailwind") - FileUtils.rm_rf(@builds_dir) if Dir.exist?(@builds_dir) - - # Save original subclasses to restore later - @original_subclasses = Rails::Engine.subclasses.dup - end - - def teardown - super - # Restore original state - Rails.application = @original_application if @original_application - - # If we've modified the Rails::Engine subclasses, restore them - if @original_subclasses - Rails::Engine.instance_variable_set(:@subclasses, @original_subclasses) - end - - # Clean up test directory - FileUtils.rm_rf(@builds_dir) if Dir.exist?(@builds_dir) - end - test "bundle creates the builds directory" do - # Store the original Rails application for restoration later - original_app = Rails.application - Dir.mktmpdir do |tmpdir| @tmpdir = tmpdir tmpdir_path = Pathname.new(tmpdir) builds_dir = tmpdir_path.join("app/assets/builds/tailwind") Rails.stub(:root, tmpdir_path) do - # Execute the bundle method Tailwindcss::Engines.bundle - - # Assert that the directory was created assert Dir.exist?(builds_dir), "Expected directory #{builds_dir} to be created" end end - - # Restore the original Rails application - Rails.application = original_app end - + test "bundle generates CSS files for engine's tailwind assets" do - # Store the original Rails application and engine subclasses - original_app = Rails.application - original_subclasses = Rails::Engine.subclasses.dup - Dir.mktmpdir do |tmpdir| @tmpdir = tmpdir tmpdir_path = Pathname.new(tmpdir) builds_dir = tmpdir_path.join("app/assets/builds/tailwind") Rails.stub(:root, tmpdir_path) do - # Create a mock engine with tailwind assets setup_mock_engine("mock_engine", tmpdir_path) - - # Execute the bundle method + Tailwindcss::Engines.bundle - - # Assert that the CSS file was generated + css_file_path = builds_dir.join("mock_engine.css") assert File.exist?(css_file_path), "Expected file #{css_file_path} to be created" - - # Check content of the generated file + content = File.read(css_file_path) assert_match(/DO NOT MODIFY THIS FILE/, content) - assert_match(/@import ".*\/app\/assets\/tailwind\/mock_engine\/application.css"/, content) + assert_match(/@import ".*\/app\/assets\/tailwind\/mock_engine\/engine.css"/, content) end end - - # Restore the original Rails application and engine subclasses - Rails.application = original_app - Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) end - + test "bundle removes existing files before generating new ones" do - # Store the original Rails application and engine subclasses - original_app = Rails.application - original_subclasses = Rails::Engine.subclasses.dup - Dir.mktmpdir do |tmpdir| @tmpdir = tmpdir tmpdir_path = Pathname.new(tmpdir) builds_dir = tmpdir_path.join("app/assets/builds/tailwind") Rails.stub(:root, tmpdir_path) do - # Create a mock engine with tailwind assets setup_mock_engine("mock_engine", tmpdir_path) - - # Create an existing file that should be replaced + FileUtils.mkdir_p(builds_dir) css_file_path = builds_dir.join("mock_engine.css") File.write(css_file_path, "OLD CONTENT") - - # Execute the bundle method + Tailwindcss::Engines.bundle - - # Assert that the old content was removed + content = File.read(css_file_path) assert_no_match(/OLD CONTENT/, content) assert_match(/DO NOT MODIFY THIS FILE/, content) end end - - # Restore the original Rails application and engine subclasses - Rails.application = original_app - Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) end - + test "bundle only processes engines with tailwind assets" do - # Store the original Rails application and engine subclasses - original_app = Rails.application - original_subclasses = Rails::Engine.subclasses.dup - Dir.mktmpdir do |tmpdir| @tmpdir = tmpdir tmpdir_path = Pathname.new(tmpdir) builds_dir = tmpdir_path.join("app/assets/builds/tailwind") Rails.stub(:root, tmpdir_path) do - # Create a mock engine with tailwind assets setup_mock_engine("engine_with_assets", tmpdir_path) - - # Create a mock engine without tailwind assets + root_path = tmpdir_path mock_engine_without_assets = Class.new(Rails::Engine) do define_singleton_method(:engine_name) { "engine_without_assets" } define_singleton_method(:root) { root_path } end Rails::Engine.instance_variable_set(:@subclasses, Rails::Engine.subclasses + [mock_engine_without_assets]) - - # Execute the bundle method + Tailwindcss::Engines.bundle - - # Assert that only the engine with assets has a CSS file generated + assert File.exist?(builds_dir.join("engine_with_assets.css")), "Expected CSS file for engine with assets" refute File.exist?(builds_dir.join("engine_without_assets.css")), "Expected no CSS file for engine without assets" end end - - # Restore the original Rails application and engine subclasses - Rails.application = original_app - Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) end - + test "bundle handles multiple engines" do - # Store the original Rails application and engine subclasses - original_app = Rails.application - original_subclasses = Rails::Engine.subclasses.dup - Dir.mktmpdir do |tmpdir| @tmpdir = tmpdir tmpdir_path = Pathname.new(tmpdir) builds_dir = tmpdir_path.join("app/assets/builds/tailwind") Rails.stub(:root, tmpdir_path) do - # Create multiple mock engines with tailwind assets setup_mock_engine("engine1", tmpdir_path) setup_mock_engine("engine2", tmpdir_path) - - # Execute the bundle method + Tailwindcss::Engines.bundle - - # Assert that CSS files were generated for both engines + assert File.exist?(builds_dir.join("engine1.css")), "Expected CSS file for engine1" assert File.exist?(builds_dir.join("engine2.css")), "Expected CSS file for engine2" end end - - # Restore the original Rails application and engine subclasses - Rails.application = original_app - Rails::Engine.instance_variable_set(:@subclasses, original_subclasses) end - + private - + def setup_mock_engine(name, root_path) - # Create a mock Rails engine with captured local variables engine_name = name path = root_path mock_engine = Class.new(Rails::Engine) do define_singleton_method(:engine_name) { engine_name } define_singleton_method(:root) { path } end - - # Create the required tailwind asset file for the mock engine + tailwind_dir = root_path.join("app/assets/tailwind/#{name}") FileUtils.mkdir_p(tailwind_dir) - File.write(tailwind_dir.join("application.css"), "/* Test CSS */") - - # Add the mock engine to Rails::Engine.subclasses - Rails::Engine.instance_variable_set(:@subclasses, Rails::Engine.subclasses + [mock_engine]) - + File.write(tailwind_dir.join("engine.css"), "/* Test CSS */") + mock_engine end -end \ No newline at end of file +end From 8a332fb09788d4b19d5bc095b7e70928592f3f89 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Thu, 12 Jun 2025 00:36:01 +0300 Subject: [PATCH 06/10] Tests cleanup --- test/lib/tailwindcss/engines_test.rb | 121 ++++++++++----------------- 1 file changed, 46 insertions(+), 75 deletions(-) diff --git a/test/lib/tailwindcss/engines_test.rb b/test/lib/tailwindcss/engines_test.rb index 9209e54b..197fff98 100644 --- a/test/lib/tailwindcss/engines_test.rb +++ b/test/lib/tailwindcss/engines_test.rb @@ -1,118 +1,89 @@ require "test_helper" +require "minitest/mock" class Tailwindcss::EnginesTest < ActiveSupport::TestCase + def setup + super + @tmpdir_path = Pathname.new(Dir.mktmpdir) + @builds_dir = @tmpdir_path.join("app/assets/builds/tailwind") + end + test "bundle creates the builds directory" do - Dir.mktmpdir do |tmpdir| - @tmpdir = tmpdir - tmpdir_path = Pathname.new(tmpdir) - builds_dir = tmpdir_path.join("app/assets/builds/tailwind") - - Rails.stub(:root, tmpdir_path) do - Tailwindcss::Engines.bundle - assert Dir.exist?(builds_dir), "Expected directory #{builds_dir} to be created" - end + Rails.stub(:root, @tmpdir_path) do + Tailwindcss::Engines.bundle + assert Dir.exist?(@builds_dir), "Expected directory #{@builds_dir} to be created" end end test "bundle generates CSS files for engine's tailwind assets" do - Dir.mktmpdir do |tmpdir| - @tmpdir = tmpdir - tmpdir_path = Pathname.new(tmpdir) - builds_dir = tmpdir_path.join("app/assets/builds/tailwind") - - Rails.stub(:root, tmpdir_path) do - setup_mock_engine("mock_engine", tmpdir_path) + Rails.stub(:root, @tmpdir_path) do + setup_mock_engine("mock_engine", @tmpdir_path) - Tailwindcss::Engines.bundle + Tailwindcss::Engines.bundle - css_file_path = builds_dir.join("mock_engine.css") - assert File.exist?(css_file_path), "Expected file #{css_file_path} to be created" + css_file_path = @builds_dir.join("mock_engine.css") + assert File.exist?(css_file_path), "Expected file #{css_file_path} to be created" - content = File.read(css_file_path) - assert_match(/DO NOT MODIFY THIS FILE/, content) - assert_match(/@import ".*\/app\/assets\/tailwind\/mock_engine\/engine.css"/, content) - end + content = File.read(css_file_path) + assert_match(/DO NOT MODIFY THIS FILE/, content) + assert_match(/@import ".*\/app\/assets\/tailwind\/mock_engine\/engine.css"/, content) end end test "bundle removes existing files before generating new ones" do - Dir.mktmpdir do |tmpdir| - @tmpdir = tmpdir - tmpdir_path = Pathname.new(tmpdir) - builds_dir = tmpdir_path.join("app/assets/builds/tailwind") - - Rails.stub(:root, tmpdir_path) do - setup_mock_engine("mock_engine", tmpdir_path) + Rails.stub(:root, @tmpdir_path) do + setup_mock_engine("mock_engine", @tmpdir_path) - FileUtils.mkdir_p(builds_dir) - css_file_path = builds_dir.join("mock_engine.css") - File.write(css_file_path, "OLD CONTENT") + FileUtils.mkdir_p(@builds_dir) + css_file_path = @builds_dir.join("mock_engine.css") + File.write(css_file_path, "OLD CONTENT") - Tailwindcss::Engines.bundle + Tailwindcss::Engines.bundle - content = File.read(css_file_path) - assert_no_match(/OLD CONTENT/, content) - assert_match(/DO NOT MODIFY THIS FILE/, content) - end + content = File.read(css_file_path) + assert_no_match(/OLD CONTENT/, content) + assert_match(/DO NOT MODIFY THIS FILE/, content) end end test "bundle only processes engines with tailwind assets" do - Dir.mktmpdir do |tmpdir| - @tmpdir = tmpdir - tmpdir_path = Pathname.new(tmpdir) - builds_dir = tmpdir_path.join("app/assets/builds/tailwind") - - Rails.stub(:root, tmpdir_path) do - setup_mock_engine("engine_with_assets", tmpdir_path) + Rails.stub(:root, @tmpdir_path) do + setup_mock_engine("engine_with_assets", @tmpdir_path) - root_path = tmpdir_path - mock_engine_without_assets = Class.new(Rails::Engine) do - define_singleton_method(:engine_name) { "engine_without_assets" } - define_singleton_method(:root) { root_path } - end - Rails::Engine.instance_variable_set(:@subclasses, Rails::Engine.subclasses + [mock_engine_without_assets]) + Class.new(Rails::Engine) do + define_singleton_method(:engine_name) { "engine_without_assets" } + define_singleton_method(:root) { Pathname.new(Dir.mktmpdir) } + end - Tailwindcss::Engines.bundle + Tailwindcss::Engines.bundle - assert File.exist?(builds_dir.join("engine_with_assets.css")), "Expected CSS file for engine with assets" - refute File.exist?(builds_dir.join("engine_without_assets.css")), "Expected no CSS file for engine without assets" - end + assert File.exist?(@builds_dir.join("engine_with_assets.css")), "Expected CSS file for engine with assets" + refute File.exist?(@builds_dir.join("engine_without_assets.css")), "Expected no CSS file for engine without assets" end end test "bundle handles multiple engines" do - Dir.mktmpdir do |tmpdir| - @tmpdir = tmpdir - tmpdir_path = Pathname.new(tmpdir) - builds_dir = tmpdir_path.join("app/assets/builds/tailwind") + Rails.stub(:root, @tmpdir_path) do + setup_mock_engine("engine1", @tmpdir_path) + setup_mock_engine("engine2", @tmpdir_path) - Rails.stub(:root, tmpdir_path) do - setup_mock_engine("engine1", tmpdir_path) - setup_mock_engine("engine2", tmpdir_path) + Tailwindcss::Engines.bundle - Tailwindcss::Engines.bundle - - assert File.exist?(builds_dir.join("engine1.css")), "Expected CSS file for engine1" - assert File.exist?(builds_dir.join("engine2.css")), "Expected CSS file for engine2" - end + assert File.exist?(@builds_dir.join("engine1.css")), "Expected CSS file for engine1" + assert File.exist?(@builds_dir.join("engine2.css")), "Expected CSS file for engine2" end end private def setup_mock_engine(name, root_path) - engine_name = name - path = root_path - mock_engine = Class.new(Rails::Engine) do - define_singleton_method(:engine_name) { engine_name } - define_singleton_method(:root) { path } - end - tailwind_dir = root_path.join("app/assets/tailwind/#{name}") FileUtils.mkdir_p(tailwind_dir) File.write(tailwind_dir.join("engine.css"), "/* Test CSS */") - mock_engine + Class.new(Rails::Engine) do + define_singleton_method(:engine_name) { name } + define_singleton_method(:root) { root_path.dup } + end end end From 656913dda34b3092b1c65921f55ec9b6e69f38e5 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Thu, 12 Jun 2025 00:38:20 +0300 Subject: [PATCH 07/10] Remove non-needed dup --- test/lib/tailwindcss/engines_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/tailwindcss/engines_test.rb b/test/lib/tailwindcss/engines_test.rb index 197fff98..50a088f9 100644 --- a/test/lib/tailwindcss/engines_test.rb +++ b/test/lib/tailwindcss/engines_test.rb @@ -83,7 +83,7 @@ def setup_mock_engine(name, root_path) Class.new(Rails::Engine) do define_singleton_method(:engine_name) { name } - define_singleton_method(:root) { root_path.dup } + define_singleton_method(:root) { root_path } end end end From 3b1f4f2a5442d8bf4fe9f56a491e2cbdf9db71f3 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Thu, 12 Jun 2025 00:40:30 +0300 Subject: [PATCH 08/10] Correction --- test/lib/tailwindcss/engines_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/tailwindcss/engines_test.rb b/test/lib/tailwindcss/engines_test.rb index 50a088f9..f4c1b0d2 100644 --- a/test/lib/tailwindcss/engines_test.rb +++ b/test/lib/tailwindcss/engines_test.rb @@ -4,7 +4,7 @@ class Tailwindcss::EnginesTest < ActiveSupport::TestCase def setup super - @tmpdir_path = Pathname.new(Dir.mktmpdir) + @tmpdir_path = Pathname.new(TAILWINDCSS_TEST_APP_ROOT) @builds_dir = @tmpdir_path.join("app/assets/builds/tailwind") end From 279c929c5582e7b4ab2914b4cd2b7f90298a73df Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Thu, 12 Jun 2025 17:05:15 +0300 Subject: [PATCH 09/10] Correct docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92af0447..910ceca7 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,7 @@ Then you can use yarn or npm to install the dependencies. ### Rails Engines support -If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../../assets/builds/tailwind/"` to your `app/assets/tailwind/application.css` file. +If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../builds/tailwind/"` to your `app/assets/tailwind/application.css` file. > [!IMPORTANT] > Only imported in `app/assets/tailwind/application.css` engine CSS files will be included in the build. By default, no engine CSS files are imported. This give you flexibility on which engine CSS files you want to include in your build. From 7fca4ba72b4f1821063440e1fe5076fd8edaf21a Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 12 Jun 2025 10:05:07 -0400 Subject: [PATCH 10/10] doc: update README to indicate engine support is experimental --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 910ceca7..274fae80 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ * [Live rebuild](#live-rebuild) * [Using Tailwind plugins](#using-tailwind-plugins) * [Using with PostCSS](#using-with-postcss) - * [Rails Engines support](#rails-engines-support) * [Custom inputs or outputs](#custom-inputs-or-outputs) + * [Rails Engines support (Experimental)](#rails-engines-support-experimental) - [Troubleshooting](#troubleshooting) * [The `watch` command is hanging](#the-watch-command-is-hanging) * [Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, `ruby/debug`...etc.) with the Puma plugin](#lost-keystrokes-or-hanging-when-using-terminal-based-debugging-tools-eg-irb-pry-rubydebugetc-with-the-puma-plugin) @@ -384,16 +384,18 @@ export default { Then you can use yarn or npm to install the dependencies. -### Rails Engines support +### Custom inputs or outputs -If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../builds/tailwind/"` to your `app/assets/tailwind/application.css` file. +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. -> [!IMPORTANT] -> Only imported in `app/assets/tailwind/application.css` engine CSS files will be included in the build. By default, no engine CSS files are imported. This give you flexibility on which engine CSS files you want to include in your build. +### Rails Engines support (Experimental) -### Custom inputs or outputs +_This feature is experimental and may change in the future. If you have feedback, please join the [discussion](https://github.com/rails/tailwindcss-rails/discussions/355)._ -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. +If you have Rails Engines in your application that use Tailwind CSS and provide an `app/assets/tailwind//engine.css` file, entry point files will be created for each of them in `app/assets/builds/tailwind/.css` so they can be included in your host application's Tailwind CSS by adding `@import "../builds/tailwind/"` to your `app/assets/tailwind/application.css` file. + +> [!IMPORTANT] +> You must `@import` the engine CSS files in your `app/assets/tailwind/application.css` for the engine to be included in the build. By default, no engine CSS files are imported, and you must opt-in to using the file in your build. ## Troubleshooting