From 8a8ce36b0e62d83f8c1cb8e1fd1b0ccb5b1713c2 Mon Sep 17 00:00:00 2001 From: Dino Maric Date: Wed, 18 Aug 2021 11:06:26 +0200 Subject: [PATCH 1/2] Remove scaffolds styles on install This stylesheet will interfere with Tailwind's reset of base styles. --- README.md | 2 -- lib/install/tailwindcss.rb | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 122ff1f7..748079f1 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ The last step adds the purger compressor to `config/environments/production.rb`. You can do these things yourself, if you've changed the default setup. -Note: You should ensure to delete `app/assets/stylesheets/scaffolds.scss` that Rails adds after running a scaffold command, if you had run this generator before installing Tailwind CSS for Rails. This stylesheet will interfere with Tailwind's reset of base styles. This gem will turn off stylesheet generation for all future scaffold runs. - ## Purging in production diff --git a/lib/install/tailwindcss.rb b/lib/install/tailwindcss.rb index e3b77d38..79f5305e 100644 --- a/lib/install/tailwindcss.rb +++ b/lib/install/tailwindcss.rb @@ -3,6 +3,9 @@ if APPLICATION_LAYOUT_PATH.exist? say "Add Tailwindcss include tags in application layout" insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, %(\n <%= stylesheet_link_tag "inter-font" %>\n <%= stylesheet_link_tag "tailwind" %>), before: /^\s*<%= stylesheet_link_tag/ + + say "Removing scaffold styles" + remove_file Rails.root.join("app/assets/stylesheets/scaffolds.scss") else say "Default application.html.erb is missing!", :red say %( Add <%= stylesheet_link_tag "inter-font" %> and <%= stylesheet_link_tag "tailwind" %> within the tag in your custom layout.) From acf005912982e4b15629ef8d0bbfeab8f88c67b4 Mon Sep 17 00:00:00 2001 From: Dino Maric Date: Wed, 18 Aug 2021 11:10:24 +0200 Subject: [PATCH 2/2] Move scaffold remove outside the contitional --- lib/install/tailwindcss.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/install/tailwindcss.rb b/lib/install/tailwindcss.rb index 79f5305e..47d28c6d 100644 --- a/lib/install/tailwindcss.rb +++ b/lib/install/tailwindcss.rb @@ -3,13 +3,13 @@ if APPLICATION_LAYOUT_PATH.exist? say "Add Tailwindcss include tags in application layout" insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, %(\n <%= stylesheet_link_tag "inter-font" %>\n <%= stylesheet_link_tag "tailwind" %>), before: /^\s*<%= stylesheet_link_tag/ - - say "Removing scaffold styles" - remove_file Rails.root.join("app/assets/stylesheets/scaffolds.scss") else say "Default application.html.erb is missing!", :red say %( Add <%= stylesheet_link_tag "inter-font" %> and <%= stylesheet_link_tag "tailwind" %> within the tag in your custom layout.) end +say "Removing scaffold styles" +remove_file Rails.root.join("app/assets/stylesheets/scaffolds.scss") + say "Turn on purging of unused css classes in production" gsub_file Rails.root.join("config/environments/production.rb"), /^\s+#?\s+config.assets.css_compressor =.*$/, %( config.assets.css_compressor = :purger)