From 5f3e115aad40a9405b4884d92b992bde2b82a358 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sat, 5 Nov 2022 13:57:05 -0300 Subject: [PATCH 1/8] add postcss param --- lib/tailwindcss/commands.rb | 1 + lib/tasks/build.rake | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index e7f34cb5..e3d5cd9b 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -63,6 +63,7 @@ def compile_command(debug: false, **kwargs) "-c", Rails.root.join("config/tailwind.config.js").to_s, ].tap do |command| command << "--minify" unless debug + command << "--postcss" if postcss end end diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index bd407214..8058042e 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -2,7 +2,8 @@ namespace :tailwindcss do desc "Build your Tailwind CSS" task :build do |_, args| debug = args.extras.include?("debug") - command = Tailwindcss::Commands.compile_command(debug: debug) + postcss = args.extras.include?("postcss") + command = Tailwindcss::Commands.compile_command(debug: debug, postcss: postcss) puts command.inspect if args.extras.include?("verbose") system(*command, exception: true) end @@ -11,7 +12,8 @@ namespace :tailwindcss do task :watch do |_, args| debug = args.extras.include?("debug") poll = args.extras.include?("poll") - command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll) + postcss = args.extras.include?("postcss") + command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll, postcss: postcss) puts command.inspect if args.extras.include?("verbose") system(*command) end From 81531b3447628cc03c6d73ee4949a28cb687bab7 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sat, 5 Nov 2022 14:20:03 -0300 Subject: [PATCH 2/8] param postcss --- lib/tailwindcss/commands.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index e3d5cd9b..06da67b8 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -1,4 +1,4 @@ -require_relative "upstream" +require_relative 'upstream' module Tailwindcss module Commands @@ -25,7 +25,7 @@ def executable( MESSAGE end - exe_path = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f| + exe_path = Dir.glob(File.expand_path(File.join(exe_path, '*', 'tailwindcss'))).find do |f| Gem::Platform.match(Gem::Platform.new(File.basename(File.dirname(f)))) end @@ -55,7 +55,7 @@ def executable( exe_path end - def compile_command(debug: false, **kwargs) + def compile_command(debug: false, postcss: false, **kwargs) [ executable(**kwargs), "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s, @@ -67,10 +67,11 @@ def compile_command(debug: false, **kwargs) end end - def watch_command(poll: false, **kwargs) + def watch_command(poll: false, postcss: false, **kwargs) compile_command(**kwargs).tap do |command| command << "-w" command << "-p" if poll + command << "--postcss" if postcss end end end From ff762b88452894750f11523498af0db3de94d971 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sat, 5 Nov 2022 15:00:01 -0300 Subject: [PATCH 3/8] postcss --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index db1a12cd..a308b653 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,10 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container, If you are running `rails tailwindcss:watch` on a system that doesn't fully support file system events, pass a `poll` argument to the task to instruct tailwindcss to instead use polling: `rails tailwindcss:watch[poll]`. If you use `bin/dev` then you should modify your `Procfile.dev`. +### Use postcss + +In the case you want to use postcss plugins you will need to pass postcss option like `rails tailwindcss:build[postcss]` or `rails tailwindcss:watch[postcss]`. + ### Debugging with unminified assets If you want unminified assets, you can pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. From dd3e0eb6d0bf06b24aa268a8fc341f439582a899 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sun, 6 Nov 2022 09:33:56 -0300 Subject: [PATCH 4/8] suppport to tailwind cli postcss, contributing tips --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a308b653..f577dba3 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container, If you are running `rails tailwindcss:watch` on a system that doesn't fully support file system events, pass a `poll` argument to the task to instruct tailwindcss to instead use polling: `rails tailwindcss:watch[poll]`. If you use `bin/dev` then you should modify your `Procfile.dev`. -### Use postcss +### Using postcss -In the case you want to use postcss plugins you will need to pass postcss option like `rails tailwindcss:build[postcss]` or `rails tailwindcss:watch[postcss]`. +The tailwind cli supports passing a postcss.config.js file. This might be necessary if you want to use postcss plugins (e.g. postcss-css-variables). In this case you can pass postcss as a task option `rails tailwindcss:build[postcss]` or `rails tailwindcss:watch[postcss]`. ### Debugging with unminified assets @@ -151,6 +151,14 @@ The inline version also works:
Has the image as it's background
``` +### Contributing + +If you want to fork this repo and test this gem locally in your projects, you will need to run `rake package` (the process this gem uses to generate platform-related gem versions, e.g. x86_64-linux, x86_64-darwin, etc). You can now point the local version of the gem in your Gemfile: + +```ruby +gem 'tailwindcss-rails', '2.0.18', path: '/path/to/your/local/gem' +``` + ## License Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT). From 7ee62328d27c5dae6a8f53297ac2d83b5d82aecf Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sun, 6 Nov 2022 09:34:13 -0300 Subject: [PATCH 5/8] make coherent quotes --- lib/tailwindcss/commands.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 06da67b8..e5d703a5 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -1,4 +1,4 @@ -require_relative 'upstream' +require_relative "upstream" module Tailwindcss module Commands @@ -25,7 +25,7 @@ def executable( MESSAGE end - exe_path = Dir.glob(File.expand_path(File.join(exe_path, '*', 'tailwindcss'))).find do |f| + exe_path = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f| Gem::Platform.match(Gem::Platform.new(File.basename(File.dirname(f)))) end From afd7dd083411dbf47f568dae4906a6103639977e Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sun, 6 Nov 2022 10:27:09 -0300 Subject: [PATCH 6/8] Bump version for 2.0.18 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 384757b4..11f31dbd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,4 +100,4 @@ DEPENDENCIES tailwindcss-rails! BUNDLED WITH - 2.3.14 + 2.3.25 From 53ab636a4eeb12dc3750bff85246180587bdcca1 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Sun, 6 Nov 2022 13:43:20 -0300 Subject: [PATCH 7/8] run with postcss in production if env var is passed --- 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 8058042e..1ca14a3f 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -2,7 +2,7 @@ namespace :tailwindcss do desc "Build your Tailwind CSS" task :build do |_, args| debug = args.extras.include?("debug") - postcss = args.extras.include?("postcss") + postcss = args.extras.include?("postcss") || !ENV['TAILWIND_POSTCSS'].blank? command = Tailwindcss::Commands.compile_command(debug: debug, postcss: postcss) puts command.inspect if args.extras.include?("verbose") system(*command, exception: true) From 5db6c3ed68ed3ce47a8a56649ae064e53233a6b1 Mon Sep 17 00:00:00 2001 From: Murilo Vasconcelos Date: Tue, 7 Feb 2023 12:02:39 -0300 Subject: [PATCH 8/8] use_postcss? --- README.md | 2 +- lib/tasks/build.rake | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f577dba3..fb1279d4 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ If you are running `rails tailwindcss:watch` on a system that doesn't fully supp ### Using postcss -The tailwind cli supports passing a postcss.config.js file. This might be necessary if you want to use postcss plugins (e.g. postcss-css-variables). In this case you can pass postcss as a task option `rails tailwindcss:build[postcss]` or `rails tailwindcss:watch[postcss]`. +The tailwind cli supports passing a postcss.config.js file. This might be necessary if you want to use postcss plugins (e.g. postcss-css-variables). This gem checks if a postcss.config.js exists, in which case it is used for building tailwind assets. ### Debugging with unminified assets diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index 1ca14a3f..e3691670 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -2,8 +2,7 @@ namespace :tailwindcss do desc "Build your Tailwind CSS" task :build do |_, args| debug = args.extras.include?("debug") - postcss = args.extras.include?("postcss") || !ENV['TAILWIND_POSTCSS'].blank? - command = Tailwindcss::Commands.compile_command(debug: debug, postcss: postcss) + command = Tailwindcss::Commands.compile_command(debug: debug, postcss: use_postcss?) puts command.inspect if args.extras.include?("verbose") system(*command, exception: true) end @@ -12,11 +11,14 @@ namespace :tailwindcss do task :watch do |_, args| debug = args.extras.include?("debug") poll = args.extras.include?("poll") - postcss = args.extras.include?("postcss") - command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll, postcss: postcss) + command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll, postcss: use_postcss?) puts command.inspect if args.extras.include?("verbose") system(*command) end + + def use_postcss? + File.exist?(Rails.root.join("postcss.config.js")) + end end Rake::Task["assets:precompile"].enhance(["tailwindcss:build"])