npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pathscale/rsbuild-plugin-ui-css-purge

v0.9.5

Published

Database-first CSS purge for `@pathscale/ui` consumers. It scans consumer JSX with SWC, cross-references a versioned component purge database, and removes only selectors whose ownership and unused state are known.

Readme

@pathscale/rsbuild-plugin-ui-css-purge

Database-first CSS purge for @pathscale/ui consumers. It scans consumer JSX with SWC, cross-references a versioned component purge database, and removes only selectors whose ownership and unused state are known.

Runs as a postbuild step under Bun.

How It Works

The purge operates in two phases across two repositories.

Lib side (@pathscale/ui): Components ship *.classes.ts files that describe component-owned classes by slot and prop. The manifest generator also scans colocated component CSS for selectors, data/aria attributes, CSS variable references, keyframes, and component dependencies. It writes a versioned purge-manifest.json database:

interface PurgeDatabaseV2 {
	version: 2;
	components: Record<string, ComponentPurgeRecord>;
	shared: {
		selectors: { selector: string; components: string[] }[];
		cssVars: Record<string, { declaredBy: string[]; referencedBy: string[] }>;
		keyframes: Record<string, { declaredBy: string[]; referencedBy: string[] }>;
	};
}

Consumer side: After rsbuild build, the CLI scans source files for canonical @pathscale/ui usage, including aliases, deep imports, namespace imports, compound JSX such as Modal.Root, re-exports, spreads, and dynamic props. It builds usage facts and applies the database conservatively.

Purge Rules

| Rule | Behavior | | --- | --- | | Unused known component | Selectors owned only by that component can be removed. | | Used component, unused prop variant | Selectors requiring that known unused class can be removed. | | Runtime data/aria state | Kept when the owning used component selector is kept. | | Unknown ownership | Kept by default. | | Theme, reset, app selectors | Kept unless they are fully known unused component selectors. | | CSS vars and keyframes | Removed only after selector purge proves they are unreferenced. |

The selector walk uses PostCSS. Lightning CSS is used for final minification.

Installation

bun add -d @pathscale/rsbuild-plugin-ui-css-purge

Usage

Consumer Project

Add the postbuild purge after rsbuild build:

{
	"scripts": {
		"build": "rsbuild build && bunx rsbuild-plugin-ui-css-purge --dist dist --src src --manifest node_modules/@pathscale/ui/dist/purge-manifest.json"
	}
}

Options:

| Flag | Default | Description | | --- | --- | --- | | --manifest | required | Path to purge-manifest.json. | | --dist | ./dist | Directory containing built CSS files. | | --src | ./src | Consumer source directory to scan for JSX usage. |

Lib-Side Manifest Generation

Run from @pathscale/ui as a build step:

{
	"scripts": {
		"prebuild": "bunx generate-manifest src/components --out dist/purge-manifest.json"
	}
}

This scans all *.classes.ts files and colocated component CSS files.

The *.classes.ts Convention

Every component should export a CLASSES object that names all component-owned classes. Tailwind utilities are filtered out so the manifest tracks ownership of durable component selectors, not generic utility classes.

// button.classes.ts
export const CLASSES = {
	base: "button inline-flex items-center",
	variant: {
		primary: "button--primary",
		secondary: "button--secondary",
	},
	size: {
		sm: "button--sm",
		md: "button--md",
	},
	flag: {
		disabled: "button--disabled",
	},
	attrs: {
		open: { "data-open": "true" },
	},
} as const;

Compound components use a nested shape:

export const CLASSES = {
	Root: { base: "modal" },
	Panel: { base: "modal__panel" },
} as const;

Programmatic API

import {
	buildSafelists,
	purgeCssWithDatabase,
	scanConsumerSource,
} from "@pathscale/rsbuild-plugin-ui-css-purge";

const usages = await scanConsumerSource("/path/to/consumer/src");
const manifest = JSON.parse(await Bun.file("purge-manifest.json").text());
const safelists = buildSafelists(usages, manifest);
const result = purgeCssWithDatabase(css, manifest, safelists);

console.log(result.report);

Development

bun install
bun run test
bun run build
bun run lint
bun run format

License

MIT