
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
vite-plugin-purgecss
Advanced tools
This Vite plugin automatically removes unused CSS based on HTML & JS output using PurgeCSS.
npm
npm i vite-plugin-purgecss
Use plugin in your Vite config (vite.config.ts
)
import htmlPurge from 'vite-plugin-purgecss'
export default {
plugins: [
htmlPurge({ ...options }),
]
}
When using frameworks that don't export to HTML (or settings styles via JS), PurgeCSS typically doesn't find anything. To fix this, I've hardcoded the plugin to feed JS code into PurgeCSS (instead of just HTML) to scan for any inlined CSS strings.
This isn't a perfect solution, as it doesn't catch explicit style changes (x.style.color = 'red';
). This could potentially be resolved with FullHuman/purgecss-from-js, but it uses CJS which is incompatible with Vite. A better solution might present itself later on.
That being said, this solution should work with most frameworks. It should even work better than a normal PurgeCSS CLI pass. I tested with SvelteKit with @sveltejs/adapter-cloudflare, and it worked flawlessly.
Optionally supply a UserDefinedOptions
as you would with PurgeCSS.
safelist
in the options object.An example of this would be Popovers in Bootstrap. Sometimes, the arrow on popovers won't be picked up by PurgeCSS, so I might set:
safelist: [ /popover/ ]
to manually whitelist all Popover related classes.
FAQs
PurgeCSS plugin for Vite
The npm package vite-plugin-purgecss receives a total of 2,628 weekly downloads. As such, vite-plugin-purgecss popularity was classified as popular.
We found that vite-plugin-purgecss demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.