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

carbon-preprocess-svelte

v0.14.4

Published

Zero-dependency Svelte preprocessors and build plugins for the Carbon Design System

Readme

carbon-preprocess-svelte

Zero-dependency Svelte preprocessors and build plugins for the Carbon Design System

It makes a carbon-components-svelte app ship less: it rewrites Carbon's barrel imports so Svelte compiles less, prunes the Carbon CSS your app can't render with the props it passes, and rewrites Carbon components for the props your app actually passes. It reads your installed Carbon, so it matches your version. Its one blind spot: a Carbon class your code builds at run time, never written as a literal bx-- token, gets pruned, so name it in safelist.

One app, built four ways (examples/vite-matrix@svelte-5):

| Variant | CSS gzip | JS gzip | | --- | --- | --- | | optimizeImports only | 93.96 kB | 152.73 kB | | optimizeCss() | 22.14 kB (-76.4%) | 152.73 kB | | plus optimizeComponents() | 22.14 kB (-76.4%) | 101.27 kB (-33.7%) | | plus hydration: false | 22.14 kB (-76.4%) | 99.51 kB (-34.8%) |

Every build says what it pruned:

$ vite build
…
carbon-preprocess-svelte: pruned Carbon CSS
  assets/index-CU4gbKFa.css  606.3 kB  →  53.2 kB  -91%

It has no dependencies, and runs on Node 22 or later, or Bun.

Quick start

npm i -D carbon-preprocess-svelte
// vite.config.js, for SvelteKit 3 (which takes its options in sveltekit())
import adapter from "@sveltejs/adapter-static";
import { sveltekit } from "@sveltejs/kit/vite";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import {
  optimizeComponents,
  optimizeCss,
  optimizeImports,
} from "carbon-preprocess-svelte";

export default {
  plugins: [
    optimizeComponents(), // before sveltekit(), which compiles what it rewrites
    sveltekit({
      preprocess: [vitePreprocess(), optimizeImports()],
      adapter: adapter(),
    }),
    optimizeCss(),
  ],
};
npx vite build    # prints the pruned stylesheets, as above

Pick a tool

Each works on its own.

| Tool | For | Does | | --- | --- | --- | | optimizeImports | any bundler, as a Svelte preprocessor | rewrites Carbon imports to source paths | | optimizeCss | Vite, SvelteKit, Astro, Rollup, Rolldown | prunes unused Carbon styles | | OptimizeCssPlugin | Webpack, Rspack | optimizeCss for Webpack and Rspack | | optimizeComponents | Vite, SvelteKit, Astro, Rollup, Rolldown | rewrites Carbon components for the props your app passes | | OptimizeComponentsPlugin | Webpack, Rspack | optimizeComponents for Webpack and Rspack | | optimizeCarbonBun | Bun.build | optimizeComponents and optimizeCss for Bun | | createCarbonOptimizer | any bundler without the plugins above | both, driven by your build script | | optimizeCarbonCss | esbuild, any post-build script | the CSS pruning as a function | | CLI | any pipeline without a plugin hook | prunes built CSS files with one command |

Without a plugin hook, run the CLI after the build:

npx carbon-preprocess-svelte optimize-css "dist/**/*.css"
npx carbon-preprocess-svelte optimize-css "dist/**/*.css" --dry-run --json

It exits 0 when done, and 2 when called wrong, given nothing to prune, or unable to read the app; --json prints the result, or the error, as one object on stdout.

Docs