From 5437db5f9fb1bd984299fec46814c1973575285f Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Fri, 13 Jun 2025 17:20:41 +0300 Subject: [PATCH 1/6] Fix read-only file system issue --- README.md | 2 +- lib/tailwindcss/engine.rb | 4 ---- lib/tasks/build.rake | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 274fae80..7788187f 100644 --- a/README.md +++ b/README.md @@ -392,7 +392,7 @@ If you need to use a custom input or output file, you can run `bundle exec tailw _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 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 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` on the first build/watch invocation 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. diff --git a/lib/tailwindcss/engine.rb b/lib/tailwindcss/engine.rb index 001004f8..7b88c5f1 100644 --- a/lib/tailwindcss/engine.rb +++ b/lib/tailwindcss/engine.rb @@ -15,9 +15,5 @@ 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/tasks/build.rake b/lib/tasks/build.rake index 603c8059..2f5a02d8 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -4,6 +4,7 @@ namespace :tailwindcss do debug = args.extras.include?("debug") verbose = args.extras.include?("verbose") + Tailwindcss::Engines.bundle command = Tailwindcss::Commands.compile_command(debug: debug) env = Tailwindcss::Commands.command_env(verbose: verbose) puts "Running: #{Shellwords.join(command)}" if verbose @@ -18,6 +19,7 @@ namespace :tailwindcss do always = args.extras.include?("always") verbose = args.extras.include?("verbose") + Tailwindcss::Engines.bundle command = Tailwindcss::Commands.watch_command(always: always, debug: debug, poll: poll) env = Tailwindcss::Commands.command_env(verbose: verbose) puts "Running: #{Shellwords.join(command)}" if verbose From ae80de9044e219b58c3dd41b2f5087fb43003b7b Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Sun, 15 Jun 2025 19:05:27 +0300 Subject: [PATCH 2/6] Changes due to review --- README.md | 48 ++++++++++++++++++++++---------------------- lib/tasks/build.rake | 11 ++++++++-- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7788187f..5f5c02b8 100644 --- a/README.md +++ b/README.md @@ -7,31 +7,31 @@ - [Installation](#installation) - * [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss) - * [Using a local installation of `tailwindcss`](#using-a-local-installation-of-tailwindcss) + - [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss) + - [Using a local installation of `tailwindcss`](#using-a-local-installation-of-tailwindcss) - [Upgrading your application from Tailwind v3 to v4](#upgrading-your-application-from-tailwind-v3-to-v4) - * [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade) - * [Upgrade steps](#upgrade-steps) - * [Troubleshooting a v4 upgrade](#troubleshooting-a-v4-upgrade) - * [Updating CSS class names for v4](#updating-css-class-names-for-v4) + - [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade) + - [Upgrade steps](#upgrade-steps) + - [Troubleshooting a v4 upgrade](#troubleshooting-a-v4-upgrade) + - [Updating CSS class names for v4](#updating-css-class-names-for-v4) - [Developing with Tailwindcss](#developing-with-tailwindcss) - * [Configuration and commands](#configuration-and-commands) - * [Building for production](#building-for-production) - * [Building for testing](#building-for-testing) - * [Building unminified assets](#building-unminified-assets) - * [Live rebuild](#live-rebuild) - * [Using Tailwind plugins](#using-tailwind-plugins) - * [Using with PostCSS](#using-with-postcss) - * [Custom inputs or outputs](#custom-inputs-or-outputs) - * [Rails Engines support (Experimental)](#rails-engines-support-experimental) + - [Configuration and commands](#configuration-and-commands) + - [Building for production](#building-for-production) + - [Building for testing](#building-for-testing) + - [Building unminified assets](#building-unminified-assets) + - [Live rebuild](#live-rebuild) + - [Using Tailwind plugins](#using-tailwind-plugins) + - [Using with PostCSS](#using-with-postcss) + - [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) - * [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely) - * [Conflict with sassc-rails](#conflict-with-sassc-rails) - * [Class names must be spelled out](#class-names-must-be-spelled-out) - * [`ERROR: Cannot find the tailwindcss executable` for supported platform](#error-cannot-find-the-tailwindcss-executable-for-supported-platform) - * [Using asset-pipeline assets](#using-asset-pipeline-assets) + - [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) + - [Class names must be spelled out](#class-names-must-be-spelled-out) + - [`ERROR: Cannot find the tailwindcss executable` for supported platform](#error-cannot-find-the-tailwindcss-executable-for-supported-platform) + - [Using asset-pipeline assets](#using-asset-pipeline-assets) - [License](#license) @@ -99,7 +99,7 @@ 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. ```ruby -# Gemfile +# Gemfile gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4 ``` @@ -392,7 +392,7 @@ If you need to use a custom input or output file, you can run `bundle exec tailw _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 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` on the first build/watch invocation 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 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` on the first build/watch invocation or manual call for `rails tailwindcss:engines` 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. diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index 2f5a02d8..00faf473 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -4,7 +4,7 @@ namespace :tailwindcss do debug = args.extras.include?("debug") verbose = args.extras.include?("verbose") - Tailwindcss::Engines.bundle + command = Tailwindcss::Commands.compile_command(debug: debug) env = Tailwindcss::Commands.command_env(verbose: verbose) puts "Running: #{Shellwords.join(command)}" if verbose @@ -19,7 +19,6 @@ namespace :tailwindcss do always = args.extras.include?("always") verbose = args.extras.include?("verbose") - Tailwindcss::Engines.bundle command = Tailwindcss::Commands.watch_command(always: always, debug: debug, poll: poll) env = Tailwindcss::Commands.command_env(verbose: verbose) puts "Running: #{Shellwords.join(command)}" if verbose @@ -28,8 +27,16 @@ namespace :tailwindcss do rescue Interrupt puts "Received interrupt, exiting tailwindcss:watch" if args.extras.include?("verbose") end + + desc "Create Rails Engines entry points" + task engines: :environment do + Tailwindcss::Engines.bundle + end end +Rake::Task["tailwindcss:build"].enhance(["tailwindcss:engines"]) +Rake::Task["tailwindcss:watch"].enhance(["tailwindcss:engines"]) + Rake::Task["assets:precompile"].enhance(["tailwindcss:build"]) if Rake::Task.task_defined?("test:prepare") From ff03c28d8e5cadb64c5d6bd1ea1e62b1e48e7ce8 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Sun, 15 Jun 2025 22:32:42 +0300 Subject: [PATCH 3/6] Restore original formatting --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5f5c02b8..450a177d 100644 --- a/README.md +++ b/README.md @@ -7,31 +7,31 @@ - [Installation](#installation) - - [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss) - - [Using a local installation of `tailwindcss`](#using-a-local-installation-of-tailwindcss) + * [Choosing a specific version of `tailwindcss`](#choosing-a-specific-version-of-tailwindcss) + * [Using a local installation of `tailwindcss`](#using-a-local-installation-of-tailwindcss) - [Upgrading your application from Tailwind v3 to v4](#upgrading-your-application-from-tailwind-v3-to-v4) - - [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade) - - [Upgrade steps](#upgrade-steps) - - [Troubleshooting a v4 upgrade](#troubleshooting-a-v4-upgrade) - - [Updating CSS class names for v4](#updating-css-class-names-for-v4) + * [You don't _have_ to upgrade](#you-dont-_have_-to-upgrade) + * [Upgrade steps](#upgrade-steps) + * [Troubleshooting a v4 upgrade](#troubleshooting-a-v4-upgrade) + * [Updating CSS class names for v4](#updating-css-class-names-for-v4) - [Developing with Tailwindcss](#developing-with-tailwindcss) - - [Configuration and commands](#configuration-and-commands) - - [Building for production](#building-for-production) - - [Building for testing](#building-for-testing) - - [Building unminified assets](#building-unminified-assets) - - [Live rebuild](#live-rebuild) - - [Using Tailwind plugins](#using-tailwind-plugins) - - [Using with PostCSS](#using-with-postcss) - - [Custom inputs or outputs](#custom-inputs-or-outputs) - - [Rails Engines support (Experimental)](#rails-engines-support-experimental) + * [Configuration and commands](#configuration-and-commands) + * [Building for production](#building-for-production) + * [Building for testing](#building-for-testing) + * [Building unminified assets](#building-unminified-assets) + * [Live rebuild](#live-rebuild) + * [Using Tailwind plugins](#using-tailwind-plugins) + * [Using with PostCSS](#using-with-postcss) + * [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) - - [Running in a docker container exits prematurely](#running-in-a-docker-container-exits-prematurely) - - [Conflict with sassc-rails](#conflict-with-sassc-rails) - - [Class names must be spelled out](#class-names-must-be-spelled-out) - - [`ERROR: Cannot find the tailwindcss executable` for supported platform](#error-cannot-find-the-tailwindcss-executable-for-supported-platform) - - [Using asset-pipeline assets](#using-asset-pipeline-assets) + * [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) + * [Class names must be spelled out](#class-names-must-be-spelled-out) + * [`ERROR: Cannot find the tailwindcss executable` for supported platform](#error-cannot-find-the-tailwindcss-executable-for-supported-platform) + * [Using asset-pipeline assets](#using-asset-pipeline-assets) - [License](#license) @@ -99,7 +99,7 @@ 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. ```ruby -# Gemfile +# Gemfile gem "tailwindcss-rails", "~> 4.0" # which transitively pins tailwindcss-ruby to v4 ``` From 6aeb1c521a83e2407a039b1c78c163cbbe98d8b3 Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Sun, 15 Jun 2025 22:36:33 +0300 Subject: [PATCH 4/6] Changes due to review --- lib/tasks/build.rake | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index 00faf473..e858b4e6 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -1,6 +1,6 @@ namespace :tailwindcss do desc "Build your Tailwind CSS" - task build: :environment do |_, args| + task build: [:environment, :engines] do |_, args| debug = args.extras.include?("debug") verbose = args.extras.include?("verbose") @@ -13,7 +13,7 @@ namespace :tailwindcss do end desc "Watch and build your Tailwind CSS on file changes" - task watch: :environment do |_, args| + task watch: [:environment, :engines] do |_, args| debug = args.extras.include?("debug") poll = args.extras.include?("poll") always = args.extras.include?("always") @@ -34,9 +34,6 @@ namespace :tailwindcss do end end -Rake::Task["tailwindcss:build"].enhance(["tailwindcss:engines"]) -Rake::Task["tailwindcss:watch"].enhance(["tailwindcss:engines"]) - Rake::Task["assets:precompile"].enhance(["tailwindcss:build"]) if Rake::Task.task_defined?("test:prepare") From 69a7621f5ac51b63ebb670037aaf55479d7d04aa Mon Sep 17 00:00:00 2001 From: Sergey Moiseev Date: Sun, 15 Jun 2025 22:39:05 +0300 Subject: [PATCH 5/6] Remove new line --- lib/tasks/build.rake | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index e858b4e6..dbb3d86b 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -4,7 +4,6 @@ namespace :tailwindcss do debug = args.extras.include?("debug") verbose = args.extras.include?("verbose") - command = Tailwindcss::Commands.compile_command(debug: debug) env = Tailwindcss::Commands.command_env(verbose: verbose) puts "Running: #{Shellwords.join(command)}" if verbose From 0ad4a24658876f7fa22f221e054518bbb6be4212 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 15 Jun 2025 22:00:00 -0400 Subject: [PATCH 6/6] Clarify "engines" rake task description --- lib/tasks/build.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index dbb3d86b..d176f2cd 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -27,7 +27,7 @@ namespace :tailwindcss do puts "Received interrupt, exiting tailwindcss:watch" if args.extras.include?("verbose") end - desc "Create Rails Engines entry points" + desc "Create Tailwind CSS entry point files for Rails Engines" task engines: :environment do Tailwindcss::Engines.bundle end