A Vite plugin (v2.0.2, latest) that encapsulates and scopes TailwindCSS styles in library builds, preventing class name clashes with consumer apps. By appending unique IDs to Tailwind classes automatically (similar to Tailwind's prefix option but automatic), it avoids the need for manual prefixing or !important hacks. Supports React with the react option and allows ignoring specific classes via regex or strings. Actively maintained, ships TypeScript types.
npm install vite-plugin-scope-tailwindVerified import paths — ran on the pinned version, not inferred.
Basic vite config using scopeTailwind with optional react and ignore options.
Upgrade to v2.0.0+ and verify that any hardcoded class references (e.g., in tests) are updated to match the new scoped format.
Replace `template: 'react'` with `react: true`.
Ensure scopeTailwind() is listed before any Tailwind-related PostCSS setup.
Wrap library components with a container class that is also scoped, or use the `ignore` option for specific classes.
Upgrade to v2.0.2+ or manually add a `declare module 'vite-plugin-scope-tailwind'` in a `.d.ts` file.
Run `npm install tailwindcss -D` and create a `postcss.config.js` with `module.exports = { plugins: { tailwindcss: {} } }`.Use `import scopeTailwind from 'vite-plugin-scope-tailwind'` or `const scopeTailwind = require('vite-plugin-scope-tailwind').default`.