diff --git a/README.md b/README.md index 274fae8..450a177 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 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/tailwindcss/engine.rb b/lib/tailwindcss/engine.rb index 001004f..7b88c5f 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 603c805..d176f2c 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") @@ -12,7 +12,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") @@ -26,6 +26,11 @@ namespace :tailwindcss do rescue Interrupt puts "Received interrupt, exiting tailwindcss:watch" if args.extras.include?("verbose") end + + desc "Create Tailwind CSS entry point files for Rails Engines" + task engines: :environment do + Tailwindcss::Engines.bundle + end end Rake::Task["assets:precompile"].enhance(["tailwindcss:build"])