A Rollup and Vite plugin that provides component-level CSS scoping for React, similar to Vue and Angular's scoped styles. Current stable version is 1.2.3 (released March 2026), updated regularly with dependency bumps. It adds a unique data attribute to JSX elements and rewrites CSS selectors to match, enabling style isolation without CSS Modules. Unlike CSS Modules, it works with preprocessors (SCSS, Less) and does not require renaming class names. Requires Node >= 18 and Vite >= 5. Ships TypeScript types.
npm install rollup-plugin-react-scoped-cssVerified import paths — ran on the pinned version, not inferred.
Set up Vite with the scoped CSS plugin and create a simple component using a .scoped.css file.
Migrate to ESM imports (import { reactScopedCssPlugin } from 'rollup-plugin-react-scoped-css') or use dynamic import().Upgrade Node to >= 18 and Vite to >= 5.
Remove `include`/`exclude` from plugin options; use Vite's `plugins` array filtering if needed.
Keep one component per file or manually ensure unique class names.
For Rollup without Vite, add @rollup/plugin-scss or similar before reactScopedCssPlugin.
Use: const [pre, post] = reactScopedCssPlugin(); plugins: [pre, /* other CSS plugins */, post]
Use import syntax or dynamic import(). If using CommonJS config file, rename to .mjs or use import() inside async function.
Install vite as devDependency: npm install -D vite. Or use in a Vite project.
Add the file extension to jsxFileExtensions option: reactScopedCssPlugin({ jsxFileExtensions: ['jsx', 'tsx', 'js'] })Use import { reactScopedCssPlugin } from '...' (named import) or check your bundler configuration.