Sha256: 5c3be44819a7b0e389ca98d7ccb787b9989f54e987fff6ce3fd8bb54b193b3c1

Contents?: true

Size: 1.39 KB

Versions: 25

Compression:

Stored size: 1.39 KB

Contents

require "open3"

module Jekyll
  module Converters
    class Tailwindcss < Converter
      safe true
      priority :low

      def matches(ext)
        /^\.css$/i.match?(ext)
      end

      def output_ext(ext)
        # At this point, we will have a CSS file
        ext
      end

      def convert(content)
        return content unless /@tailwind/i.match?(content)

        dev_mode = Jekyll.env == "development"
        Jekyll.logger.info "Jekyll Tailwind:", "Generating #{dev_mode ? "" : "minified "}CSS"

        compile_command = ::Tailwindcss::Commands.compile_command(debug: dev_mode).join(" ")

        output, error = nil
        Open3.popen3(tailwindcss_env_options, compile_command) do |stdin, stdout, stderr, _wait_thread|
          stdin.write content # write the content of *.tailwindcss to the tailwindcss CLI as input
          stdin.close
          error = stderr.read
          output = stdout.read
        end
        Jekyll.logger.warn "Jekyll Tailwind:", error unless error.nil?

        output
      rescue => e
        Jekyll.logger.error "Jekyll Tailwind:", e.message
        content
      end

      private

      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.
        {"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
jekyll-tailwindcss-0.4.0 lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1 lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-x86_64-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-x86_64-darwin lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-x64-mingw32 lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-x64-mingw-ucrt lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-arm64-darwin lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-arm-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.1-aarch64-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0 lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-x86_64-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-x86_64-darwin lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-x64-mingw32 lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-x64-mingw-ucrt lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-arm64-darwin lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-arm-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.3.0-aarch64-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.2.0-x86_64-linux lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.2.0-x86_64-darwin lib/jekyll/converters/tailwindcss.rb
jekyll-tailwindcss-0.2.0-x64-mingw32 lib/jekyll/converters/tailwindcss.rb