dolanmiu / vite-plugin-scope-tailwind

Encapsulate and scope your TailwindCSS styles to your library and prevent them affecting styles outside.
23 stars 3 forks source link

vite-plugin-scope-tailwind

NPM version Downloads per month GitHub Action Workflow Status Known Vulnerabilities PRs Welcome codecov

Encapsulate and scope your TailwindCSS styles to your library and prevent them affecting styles outside.

Love using TailwindCSS? Other people also love using TailwindCSS? Trying to mix them together? Usually this leads to problems as the tailwind classes such as flex, bg-red-500 will clash and change specificity.

Potential solutions:

Installation

npm i vite-plugin-scope-tailwind -D

Usage

vite-plugin-scope-tailwind to the rescue!

This plugin scopes/encapsulates/contains all the TailwindCSS styles of your library all in, without any extra hacking around.

Add the scopeTailwind plugin into the plugins list in your vite.config.js:

import scopeTailwind from "vite-plugin-scope-tailwind";

export default defineConfig({
    ...
    plugins: [
        ...
        scopeTailwind(), // or scopeTailwind({ react: true }) for a React app
        ...
    ],
    ...
});

Options

{
    react: boolean // If your app is a React app
    ignore: RegExp | RegExp[] | string | string[] // If you want to exclude some classes from being scoped
}

Made with ❤️