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 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-bs-tailwind

v0.2.2

Published

A PostCSS plugin for generating Tailwind CSS types for BuckleScript/ReasonML

Downloads

3

Readme

postcss-bs-tailwind

A PostCSS plugin for generating ReasonML variables that correspond to Tailwind CSS classnames.

What does this plugin do?

This plugin generates a Tailwind.re module for you that contains a binding for each and every Tailwind class in your CSS. So, instead of relying on strings in your code (which can be prone to typos), you get the safety (and the auto-complete) of a variable! And, thanks to BuckleScript's [@bs.inline] directive, the bindings have zero runtime cost! They complile to plain strings!

Installation and Configuration

This codegen tool works best when you're using re-classnames, which is a ReasonML implementation of the popular classnames library for composing classes into a string you can pass to the className prop on a DOM node. The examples bellow assume you've followed re-classname's installation instructions.

npm install postcss-bs-tailwind re-classnames

# or

yarn add postcss-bs-tailwind re-classnames

Then, update your PostCSS config to look something like this:

const tailwindcss = require("tailwindcss");
const reason = require("postcss-bs-tailwind");

module.exports = {
  plugins: [
    tailwindcss("./tailwind.config.js"),
    require("autoprefixer"),
    reason({ modulePath: "./bindings/Tailwind.re" })
  ]
};

Important: Make sure this plugin appears after your tailwindcss plugin, preferably last in the list.

The modulePath config value is required, and denotes the name/location where you'd like the generated module. Now, when you run PostCSS, you'll end up with a Reason module that looks like this:

// ...
[@bs.inline] let bg_cyan_050 = "bg-cyan-050";
[@bs.inline] let bg_cyan_100 = "bg-cyan-100";
[@bs.inline] let bg_cyan_200 = "bg-cyan-200";
[@bs.inline] let bg_cyan_300 = "bg-cyan-300";
// ...

So now, in your ReasonReact code, you can do:

open Tailwind;

[@react.component]
let make = () => {
  <button className=Cn.make([bg_cyan_300])> "Cyan Button"->React.string </button>
};

Name Mapping

Tailwind's default naming scheme isn't compatible with Reason's syntax, so each name gets changed a little:

| Tailwind Class | Reason Variable | Naming Rule | | ----------------- | -------------------- | ---------------------------------------------------------------------------------------------- | | bg-blue-100 | bg_blue_100 | - gets changed to _ | | focus:bg-blue-100 | focus__bg_blue_050 | : gets changed to __ | | -m-1 | neg_m_1 | - as a prefix gets changed to neg_ | | w-1/2 | w_one_half | 1/2 gets changed to one_half (other fractions get replaced with their text representation) |

Don't worry - the Reason varaible is only a placeholder for the actual string value! When your Reason code is compliled to JS, the original Tailwind string will be right where you expect it!

Custom Tailwind Stuff

No worries! This plugin works by parsing the CSS after Tailwind CSS is generated. It walks through each class definition in your CSS code and transforms the class' name into something that's Reason-friendly. So, any special classes you've got (from Tailwind plugins or custom config) should get picked up just fine. That said, there could be some naming edge cases that aren't handled as of yet. Feel free to open an issue if you bump into one!