From 63ba740ba17fc96e22d03ad429bae9bb9eb81e4d Mon Sep 17 00:00:00 2001 From: Ilgiz Mustafin Date: Mon, 24 Feb 2025 15:15:34 +0100 Subject: [PATCH] Handle plugins in v3 detection --- CHANGELOG.md | 2 ++ lib/jekyll/converters/tailwindcss.rb | 8 +++++++- spec/jekyll/converters/tailwindcss_spec.rb | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d01fea..f1d30b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Support importing official plugins in CSS for v4 [#22](https://github.com/vormwald/jekyll-tailwindcss/pull/22) @imustafin + ## [0.6.1] - 2025-02-13 - Expand the matcher to match additional valid tailwindcss imports [#21](https://github.com/vormwald/jekyll-tailwindcss/pull/21) diff --git a/lib/jekyll/converters/tailwindcss.rb b/lib/jekyll/converters/tailwindcss.rb index c7ad25c..bccbc57 100644 --- a/lib/jekyll/converters/tailwindcss.rb +++ b/lib/jekyll/converters/tailwindcss.rb @@ -17,7 +17,7 @@ def output_ext(ext) def convert(content) return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content) - if content.include?("@tailwind") && config_path.nil? + if config_path.nil? && tailwind_v3_syntax?(content) Jekyll.logger.error "Jekyll Tailwind:", "to use tailwind v3 you need to include a config path in _config.yml" return content end @@ -46,6 +46,12 @@ def convert(content) private + def tailwind_v3_syntax?(content) + return false if content.include?("@plugin") + + content.include?("@tailwind") + end + def tailwindcss_env_options # Without this ENV you'll get a warning about `Browserslist: caniuse-lite is outdated` # Since we're using the CLI, we can't update the data, so we ignore it. diff --git a/spec/jekyll/converters/tailwindcss_spec.rb b/spec/jekyll/converters/tailwindcss_spec.rb index f8fb190..ea21e3b 100644 --- a/spec/jekyll/converters/tailwindcss_spec.rb +++ b/spec/jekyll/converters/tailwindcss_spec.rb @@ -88,6 +88,24 @@ end end + context "when using official plugins" do + let(:tailwindcss_content) do + # Example installation configuration for + # https://github.com/tailwindlabs/tailwindcss-typography + <<~TAILWINDCSS + @import "tailwindcss"; + @plugin "@tailwindcss/typography"; + TAILWINDCSS + end + + it "does not produce errors" do + expect(Jekyll.logger).not_to receive(:error).with("Jekyll Tailwind:", /v3/) + expect(Jekyll.logger).to receive(:info).with("Jekyll Tailwind:", "Generating CSS") + + converter.convert(tailwindcss_content) + end + end + context "when using TailwindCSS v3" do let(:tailwindcss_content) do <<~TAILWINDCSS