From 6dd82b60d15ad49c4b0359f30b33ca693d97d2ed Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 29 Apr 2024 23:33:30 +0200 Subject: [PATCH] Enable server process only for new installs --- lib/install/tailwindcss.rb | 9 +++++++++ lib/tailwindcss/engine.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/install/tailwindcss.rb b/lib/install/tailwindcss.rb index 413f86b8..21083faa 100644 --- a/lib/install/tailwindcss.rb +++ b/lib/install/tailwindcss.rb @@ -1,5 +1,6 @@ APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb") CENTERING_CONTAINER_INSERTION_POINT = /^\s*<%= yield %>/.freeze +DEVELOPMENT_ENVIRONMENT_CONFIG_PATH = Rails.root.join("config/environments/development.rb") if APPLICATION_LAYOUT_PATH.exist? say "Add Tailwindcss include tags and container element in application layout" @@ -16,6 +17,14 @@ say %( Add <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> within the tag in your custom layout.) end +if DEVELOPMENT_ENVIRONMENT_CONFIG_PATH.exists? + say "Enable Tailwindcss server process in development" + insert_into_file DEVELOPMENT_ENVIRONMENT_CONFIG_PATH.to_s, <<~ERB.indent(2), before: /^end$/ + # Automatically watch and build Tailwindcss when 'rails server' is started. + config.tailwindcss.server_process = true + ERB +end + say "Build into app/assets/builds" empty_directory "app/assets/builds" keep_file "app/assets/builds" diff --git a/lib/tailwindcss/engine.rb b/lib/tailwindcss/engine.rb index 99e0c82e..fb60f1e3 100644 --- a/lib/tailwindcss/engine.rb +++ b/lib/tailwindcss/engine.rb @@ -3,7 +3,7 @@ module Tailwindcss class Engine < ::Rails::Engine config.tailwindcss = ActiveSupport::OrderedOptions.new - config.tailwindcss.server_process = Rails.env.development? + config.tailwindcss.server_process = false # Rails.env.development? initializer "tailwindcss.assets" do Rails.application.config.assets.precompile += %w( inter-font.css )