# @erbelion/vite-plugin-laravel-purgecss

> A Vite plugin that integrates PurgeCSS with Laravel template assets.

Latest version **0.4.8** (published 2026-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @erbelion/vite-plugin-laravel-purgecss
pnpm add @erbelion/vite-plugin-laravel-purgecss
yarn add @erbelion/vite-plugin-laravel-purgecss
bun add @erbelion/vite-plugin-laravel-purgecss
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.8 |
| Published | 2026-04-27 |
| First published | 2022-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 30.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | erbelion |
| Maintainers | erbelion |
| Keywords | vite, vite-plugin, purgecss, laravel |

## Links

- npm: https://www.npmjs.com/package/@erbelion/vite-plugin-laravel-purgecss
- Repository: https://github.com/erbelion/vite-plugin-laravel-purgecss
- Homepage: https://github.com/erbelion/vite-plugin-laravel-purgecss#readme
- Issues: https://github.com/erbelion/vite-plugin-laravel-purgecss/issues
- npm.io page: https://npm.io/package/@erbelion/vite-plugin-laravel-purgecss

## Dependencies (1)

- [purgecss](https://npm.io/package/purgecss.md) ^8.0.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.4.8 (latest) — 2026-04-27
- 0.4.7 — 2026-02-11
- 0.4.4 — 2025-11-16
- 0.4.2 — 2025-07-27
- 0.4.0 — 2025-06-10
- 0.3.4 — 2024-12-13
- 0.3.3 — 2024-11-29
- 0.3.2 — 2024-11-15
- 0.2.6 — 2024-11-15
- 0.2.5 — 2024-05-07
- 0.2.3 — 2023-11-21
- 0.2.2 — 2023-06-19
- 0.2.1 — 2023-06-16
- 0.1.4 — 2023-03-04
- 0.1.2 — 2023-01-21
- … 2 more at https://npm.io/package/@erbelion/vite-plugin-laravel-purgecss/versions

## README

# vite-plugin-laravel-purgecss

[![Get package from npm](https://img.shields.io/npm/v/@erbelion/vite-plugin-laravel-purgecss?logo=npm&logoColor=white&style=flat&label=)](https://www.npmjs.com/package/@erbelion/vite-plugin-laravel-purgecss) [![Downloads](https://img.shields.io/npm/dt/@erbelion/vite-plugin-laravel-purgecss?color=blue&label=&logoColor=white&style=flat&logo=data:image/svg%2bxml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmIj48ZyBpZD0iU1ZHUmVwb19iZ0NhcnJpZXIiIHN0cm9rZS13aWR0aD0iMCI+PC9nPjxnIGlkPSJTVkdSZXBvX3RyYWNlckNhcnJpZXIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PC9nPjxnIGlkPSJTVkdSZXBvX2ljb25DYXJyaWVyIj4gPHBhdGggZD0iTTEyLjUgNFYxN00xMi41IDE3TDcgMTIuMjEwNU0xMi41IDE3TDE4IDEyLjIxMDUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD4gPHBhdGggZD0iTTYgMjFIMTkiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD4gPC9nPjwvc3ZnPg==)](https://www.npmjs.com/package/@erbelion/vite-plugin-laravel-purgecss) [![Downloads](https://img.shields.io/npm/dw/@erbelion/vite-plugin-laravel-purgecss?color=blue&label=&logoColor=white&style=flat&logo=data:image/svg%2bxml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmIj48ZyBpZD0iU1ZHUmVwb19iZ0NhcnJpZXIiIHN0cm9rZS13aWR0aD0iMCI+PC9nPjxnIGlkPSJTVkdSZXBvX3RyYWNlckNhcnJpZXIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PC9nPjxnIGlkPSJTVkdSZXBvX2ljb25DYXJyaWVyIj4gPHBhdGggZD0iTTEyLjUgNFYxN00xMi41IDE3TDcgMTIuMjEwNU0xMi41IDE3TDE4IDEyLjIxMDUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD4gPHBhdGggZD0iTTYgMjFIMTkiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjwvcGF0aD4gPC9nPjwvc3ZnPg==)](https://www.npmjs.com/package/@erbelion/vite-plugin-laravel-purgecss) [![views](https://views.erbek.space/api/views.svg?id=github.com%2Ferbelion%2Fvite-plugin-laravel-purgecss)](https://views.erbek.space/page/?id=github.com%2Ferbelion%2Fvite-plugin-laravel-purgecss)

A [Vite](https://github.com/vitejs/vite) plugin that integrates [PurgeCSS](https://github.com/FullHuman/purgecss) with [Laravel 9-13](https://github.com/laravel/laravel) template assets (currently updated up to laravel/laravel@13.1.0).

This plugin purges unused CSS assets only in production mode (`pnpm build` / `yarn build` / `npm run build`).

## 📦 Installation

**Using pnpm:**

```bash
pnpm add -D @erbelion/vite-plugin-laravel-purgecss
```

**Using yarn:**

```bash
yarn add -D @erbelion/vite-plugin-laravel-purgecss
```

**Using npm:**

```bash
npm i -D @erbelion/vite-plugin-laravel-purgecss
```

## 🚀 Usage

To use the plugin in your Vite configuration (`vite.config.ts`):

```typescript
import purge from '@erbelion/vite-plugin-laravel-purgecss'

export default {
    plugins: [
        laravel(...),
        purge()
    ]
}
```

**[See more examples](#-other-examples)**

## 🛠️ Options

| Parameter        | Type                          | Optional | Description                                                                                                                            |
| ---------------- | ----------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| paths            | `string[]`                    | Yes      | List of paths to be processed by PurgeCSS.                                                                                             |
| rehash           | `boolean`                     | Yes      | Determines whether to hash asset filenames after purging.                                                                              |
| PurgeCSS Options | `Partial<UserDefinedOptions>` | Yes      | PurgeCSS options [(see docs)](https://purgecss.com/configuration.html#options).                                                        |
| templates        | `string[]`                    | Yes      | ❌ Deprecated [(see anyway)](https://github.com/erbelion/vite-plugin-laravel-purgecss/blob/main/src/deprecated/DEPRECATED-OPTIONS.md). |

### `paths` Option

If the `paths` option isn't specified, it will default to:

```text
resources/{js,views}/**/*.{blade.php,svelte,vue,html}
```

### `rehash` Option (experimental)

If the `rehash` option isn't specified, it will default to `false`.

> ⚠️ **Experimental** — `rehash` patches `manifest.json` on disk after Vite writes it. This relies on assumptions about Vite's output format that may break across Vite versions.

**Why does `rehash` exist?**

Vite hashes CSS filenames based on the **unprocessed SCSS/CSS source** at build time (e.g. `app-B2qGsMUw.css`).
That hash does **not** change when you add a new class to a Blade template — even though PurgeCSS
will now include additional rules in the output.

Without `rehash`, a browser or CDN that cached the old CSS file would never know to re-fetch it,
because the filename is identical despite different content.

With `rehash` enabled, the plugin appends an additional hash derived from the **purged CSS content**
(e.g. `app-B2qGsMUw-e5ec2996.css`) and patches `manifest.json` accordingly.

### All Options

```typescript
type Options = {
    // Plugin options
    paths?: string[] // Defaults to `resources/{js,views}/**/*.{blade.php,svelte,vue,html}`
    rehash?: boolean // Defaults to `true`
    templates?: string[] // ❌ Deprecated

    // PurgeCSS options
    defaultExtractor?: ExtractorFunction
    extractors?: Array<Extractors>
    fontFace?: boolean
    keyframes?: boolean
    output?: string
    rejected?: boolean
    rejectedCss?: boolean
    stdin?: boolean
    stdout?: boolean
    variables?: boolean
    safelist?: UserDefinedSafelist
    blocklist?: StringRegExpArray
}
```

## 💡 Other Examples

**Via custom path:**

```typescript
purge({
    paths: ["resources/{js,views}/**/*.{blade.php,svelte,vue,html}"],
})
```

**Via custom paths + safe list styling:** (always keep `#bruh`, `.nice-button`, and `h1` styling)

```typescript
purge({
    paths: ["resources/views/**/*.blade.php", "resources/{js,views}/**/*.vue"],
    safelist: ["bruh", "nice-button", "h1"],
})
```

**Example config with fix for escaped prefixes (`sm:`, `lg:`, etc.):**

```typescript
purge({
    extractors: [
        {
            extractor: (content) => {
                return content.match(/[a-z-_:\/]+/g) || []
            },
            extensions: ["php", "vue", "html"],
        },
    ],
})
```

## 📚 Tutorial

[https://github.com/erbelion/tutorial-vite-plugin-laravel-purgecss](https://github.com/erbelion/tutorial-vite-plugin-laravel-purgecss#tutorial-vite-plugin-laravel-purgecss)

## 👉 See Also

- [vite-plugin-sveltekit-purgecss](https://github.com/erbelion/vite-plugin-sveltekit-purgecss)

---
_Source: https://npm.io/package/@erbelion/vite-plugin-laravel-purgecss · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
