🔄 Tailwind to CSS (tw-to-css)
Transform Tailwind classes to pure CSS using our plug-and-play package, compatible with both CSR and SSR. The package also includes the option to convert the output to JSON for use with React or other tools.
Installation
NPM module
npm install tw-to-css -E
yarn add tw-to-css -E
CDN
<script src="https://unpkg.com/tw-to-css@0.0.1/dist/cdn.min.js"></script>
Usage
import { twi, twj } from "tw-to-css";
const styleInline = twi(`bg-white mx-auto`);
const styleJSON = twj(`bg-white mx-auto`);
The first parameter expects the content
, which can be in string
or string[]
format.
twi
and twj
functions take an additional options object that allows you to configure the output.
Options:
minify | boolean | true | Compresses the CSS code |
merge | boolean | true | Combines all generated CSS classes into a single style block. |
Example:
twi("bg-white mx-auto", { minify: false, merge: false });
You can also configure your own Tailwind config using the tailwindToCSS function:
import { tailwindToCSS } from "tw-to-css";
const { twi, twj } = tailwindToCSS({
config: {
theme: {
extend: {
colors: {
"custom-color": "#ff0000",
},
},
},
},
});
Example of usage with React:
import * as React from "react";
import { twj } from "tw-to-css";
export default function EmailTemplate() {
return (
<html>
<body style={twj("font-sans text-md bg-white py-4")}>
<h1 style={twj("text-black text-center p-0 my-2 mx-0")}>Tailwind to CSS!</h1>
<p style={twj("text-gray-400 text-center")}>Transform Tailwind classes to pure CSS</p>
</body>
</html>
);
}