Socket
Book a DemoInstallSign in
Socket

gatsby-theme-tailwindcss

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-theme-tailwindcss

Gatsby Tailwind Theme

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
7
16.67%
Maintainers
1
Weekly downloads
 
Created
Source

Gatsby

Gatsby Tailwind Theme

A Gatsby theme to use tailwindcss.

Demo site

Summary

This theme installs:

Tailwindcss and postcss are required to have tailwind properly working, emotion is installed because it is very common to use a CSS in JS framework and I think it is useful to have emotion and tailwind installed and configured to work together.

Installation

Manually add to your site

npm install --save gatsby-theme-tailwindcss

or

yarn add gatsby-theme-tailwindcss

Usage

Add Tailwind to your CSS

As stated on its official documentation, inject Tailwind's styles using the @tailwind directive:

@tailwind base;

@tailwind components;

@tailwind utilities;

You should write these 3 directives either on a css you are importing or creating a new .css file and importing it.

I recommend creating a globals.css file for example in a utils folder and use it for tailwind loading directives and later extracting CSS components and / or other customisations if needed.

├── gatsby-config.js
├── node_modules
├── package.json
└── src
    ├── pages
    │   └── index.js
    └── utils
        └── globals.css

NOTE: If you experience a FOUC (flash of unstyled content) when first loading pages, import the above mentioned .css file on gatsby-browser.js, like this:

//gatsby-browser.js
import "./src/utils/globals.css"

Configuration

Add a tailwind.config.js file at the root of your project folder in order to use the tailwind.macro for CSS in JS and to be able to customise the tailwind base styles and modifiers.

yarn tailwind init

or

npx tailwindcss init

Theme options

This theme is using gatsby-plugin-postcss under the hood, so you can pass in any options you would to the actual postcss plugin (postCssPlugins and cssLoaderOptions)

NOTE: using a postcss.config.js file is not supported, you have to use the options: {} object of the theme.
KeyDefault valueDescription
postCssPlugins[require("tailwindcss")]postcss-plugins to load
cssLoaderOptions{}postcss css loader options
emotionOptions{}emotion babel-plugin-emotion options

Example usage

The only plugin included as default is the actual tailwindcss required to work, but I do recommend using the autoprefixer and purgeCSS plugins too.

With autoprefixer

(See it in action in the demo site)

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-theme-tailwindcss`,
      options: {
        postCssPlugins: [require("autoprefixer")],
      },
    },
  ],
}

With purgeCSS

(See it in action in the demo site)

Use the official gatsby plugin gatsby-plugin-purgecss

For more detailed info, visit the official docs at tailwindcss docs

Keywords

gatsby

FAQs

Package last updated on 15 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.