npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@blockhandbook/tailwindcss

v0.2.28

Published

Utilities that make it easy to add Tailwindcss to a WordPress block editor plugin

Readme

Easily add Tailwindcss to a WordPress block editor plugin

This is a collection of utilities that make it easy to add Tailwindcss to your WordPress block editor plugin.

Installation

npm i @blockhandbook/tailwindcss --save-dev

This package assumes that your code will run in an ES2015+ environment.

Setup

Add postcss.config.js, tailwind.config.js, & a package.json file to your root directory:

touch postcss.config.js && touch tailwind.config.js && npm init

Add an assets directory in src, a css directory in assets, and create a tailwind.css file:

plugin-name
├── build
├── src
│    ├── assets
│    |   └── css
│    |       └── tailwind.css
│    └── blocks
│        └── block
│            └── index.js
├── plugin-name.php
├── tailwind.config.js
├── postcss.config.js
└── package.json

Add the following to the tailwind.css file ( I leave the @tailwind base styles out but you can uncomment those if you want them ):

/*
 tailwindcss styles and custom components
*/
/* @tailwind base; */

@tailwind components;

@tailwind utilities;

Set your postcss configurations in postcss.config.js. Add your plugin slug in the postcssPrependSelector selector key. This will allow you to use ANY tailwindcss classes scoped to your custom build gutenberg blocks without them leaking to the rest of the page. Also, if you put your tailwind.config.js file in a different directory, you'll want to update that here too:

const tailwindcss = require( 'tailwindcss' );
const autoprefixer = require( 'autoprefixer' );

const postcssPrependSelector = require( 'postcss-prepend-selector' )( {
 selector: '[class*="plugin-slug"] ',
} );

module.exports = {
 plugins: [
  tailwindcss( './tailwind.config.js' ),
  postcssPrependSelector,
  autoprefixer,
 ],
};

Add tailwindcss configurations in the tailwind.config.js file. Change the purge > content array if you're using a different file structure:

const nodeEnv = process.env.NODE_ENV;

const config = {
 theme: {},
 variants: {},
 purge: {
  enabled: nodeEnv === 'production' ? true : false,
  content: [
   './src/**/*.js',
  ],
 },
 plugins: [
  require( 'tailwindcss' ),
  require( 'autoprefixer' )
 ],
};

module.exports = config;

Finally, add a build and start script to your package.json. I'm going to assume you're using @wordpress/scripts for starting/building your plugin:

{
 "name": "plugin-name",
 "scripts": {
   "start": "wp-scripts start & npm run tailwind:watch",
   "build": "wp-scripts build && npm run tailwind:build",
   "tailwind:watch":"cross-env NODE_ENV=development postcss --config ./postcss.config.js ./src/assets/css/tailwind.css -o ./build/tailwind.css -w",
   "tailwind:build":"cross-env NODE_ENV=production postcss --config ./postcss.config.js ./src/assets/css/tailwind.css -o ./build/tailwind.css"
 }
}

The classnames package is baked in so you can conditionally include/exclude tailwindcss classes. I particularly love using it for providing preset stylings for properties such as boxShadow, borderRadius, borderWidth, etc.:

const rowClasses = classnames(
  `p-10 bg-white ${ borderStyle.style } overflow-hidden`,
  {
   [ `${ borderRadius.preset }` ]: borderRadius.usePreset,
   [ `${ borderWidth.preset }` ]: borderWidth.usePreset,
   [ `${ boxShadow.preset }` ]: boxShadow.usePreset,
  }
 );

Usage

To use in development run:

npm run start

To use in production run:

npm run build

Controls

Checkout @blockhandbook/tailwindcss-controls for a library of common block styling controls powered by tailwindcss classes: