Babel Plugin Tailwind Components screenshot

Babel Plugin Tailwind Components

Author Avatar Theme by Bradlc
Updated: 8 Oct 2018
336 Stars

Use Tailwind with any CSS-in-JS library

Overview:

The babel-plugin-tailwind-components npm package allows users to use Tailwind CSS with any CSS-in-JS library. It requires a Tailwind config file and can be installed and used either via babel-plugin-macros or without it. The plugin transforms the tagged template literals into a style object which is compatible with most CSS-in-JS libraries.

Features:

  • Use Tailwind CSS with any CSS-in-JS library
  • Supports styled-components, emotion, glamor, and styled-jsx
  • Transforms tagged template literals into a style object
  • Compatible with most CSS-in-JS libraries

Installation:

  1. Ensure you have a Tailwind config file. If you don’t have one, you can grab the default config from the Tailwind repo.
  2. Place the config file in your project root as tailwind.js. Alternatively, you can specify a different filename in the plugin options.
  3. Install babel-plugin-tailwind-components and @babel/plugin-syntax-object-rest-spread if you haven’t already.
  4. If you want to use babel-plugin-macros:
    • Install babel-plugin-macros and add it to your babel config.
    • Import tailwind.macro to use Tailwind classes with your preferred CSS-in-JS library.
  5. If you want to use the plugin without babel-plugin-macros:
    • Install babel-plugin-tailwind-components and add it to your babel config.
    • The tw tag is now available anywhere without an explicit import.

Summary:

The babel-plugin-tailwind-components npm package provides a convenient way to use Tailwind CSS with any CSS-in-JS library. It transforms tagged template literals into a style object that is compatible with most CSS-in-JS libraries. The plugin can be installed and used either with or without babel-plugin-macros. It requires a Tailwind config file and provides options for customization. Overall, this package simplifies the integration of Tailwind CSS into CSS-in-JS workflows.