
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
rollup-plugin-purgecss-sveltekit
Advanced tools
A simple rollup plugin that throughly purges excess CSS from Svelte projects using PurgeCSS. Excellent when combining Tailwind with a Tailwind specific UI library such as Skeleton.
PurgeCSS is a great package that does its job very well. Their provided plugins for extraction do a decent job for simple projects. However, plugins such as postcss-purgecss and rollup-plugin-purgecss do their jobs rather naively. They only analyze the content that is passed to them through their content fields, which means that if you pass a UI library to it, none of the selectors that are unused in your project (such as components that aren't imported) will be properly purged. Leaving you with a larger than necessary CSS bundle.
Ideally, we'd like to only keep the selectors that are used in your project, and only the ones that are imported from a library. We accomplish this by walking Svelte's AST, extracting out any the possible selectors (thanks to code lifted from carbon-preprocess-svelte's optimizeCss() plugin), followed by the extraction of potential selectors from the emitted JS chunks from rollup. From there, we can pass along the selectors to PurgeCSS for the final extraction.
npm i -D rollup-plugin-purgecss-sveltekit
// vite.config.ts
import { purgeCss } from "rollup-plugin-purgecss-sveltekit";
const config: UserConfig = {
plugins: [
sveltekit(),
process.env.NODE_ENV === "production" && purgeCss(), // we only want it to run in production
],
};
If selectors that shouldn't be purged are being removed, simply add them to the safelist.
// vite.config.ts
import { purgeCss } from "rollup-plugin-purgecss-sveltekit";
const config: UserConfig = {
plugins: [
sveltekit(),
process.env.NODE_ENV === "production" &&
purgeCss({
safelist: {
// any selectors that begin with "hljs-" will not be purged
greedy: [/^hljs-/],
},
}),
],
};
Foundationally based from carbon-preprocess-svelte for the preprocessing of svelte components. We've added further logic to include selectors that may live in JS/TS files as well.
FAQs
PurgeCSS for SvelteKit
We found that rollup-plugin-purgecss-sveltekit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.