Home > rollup-plugin-purgecss > pluginPurgeCSS
pluginPurgeCSS() function
Rollup plugin removing the unused CSS of the imported CSS files.
Signature:
declare function pluginPurgeCSS(options?: UserDefinedOptions): Plugin;
Parameters
Parameter | Type | Description |
|---|---|---|
options | (Optional) options |
Returns:
Plugin
the plugin
Remarks
Works with Rollup, Rolldown and Vite.
With Rollup and Rolldown, each imported CSS file becomes a JS module. Its default export is the purged CSS, an empty string when the CSS is written to output, and the CSS is inserted in the page with insert. The content files are watched: in watch mode, a change to one of them purges the CSS again.
With Vite, the plugin must be in the plugins array of the Vite config, not in build.rolldownOptions.plugins. The purged CSS is handed back to Vite's CSS pipeline, which bundles and minifies it. Relative paths of content and output are resolved from Vite's root. The plugin does nothing with vite serve, and leaves CSS modules (*.module.css) untouched as Vite has already renamed their classes.
