@erbelion/vite-plugin-laravel-purgecss

中文文档
0.4.8发布于 2026/04/28MITTypeScriptESM + CJS近 30 天下载 6336

A Vite plugin that integrates PurgeCSS with Laravel template assets.

原始使用文档
文档目录9 节
  1. 📦 Installation
  2. 🚀 Usage
  3. 🛠️ Options
  4. paths Option
  5. rehash Option (experimental)
  6. All Options
  7. 💡 Other Examples
  8. 📚 Tutorial
  9. 👉 See Also

vite-plugin-laravel-purgecss

Get package from npm Downloads Downloads views

A Vite plugin that integrates PurgeCSS with Laravel 9-13 template assets (currently updated up to laravel/[email protected]).

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

📦 Installation

Using pnpm:

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

Using yarn:

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

Using npm:

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

🚀 Usage

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

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

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

See more examples

🛠️ Options

ParameterTypeOptionalDescription
pathsstring[]YesList of paths to be processed by PurgeCSS.
rehashbooleanYesDetermines whether to hash asset filenames after purging.
PurgeCSS OptionsPartial<UserDefinedOptions>YesPurgeCSS options (see docs).
templatesstring[]Yes❌ Deprecated (see anyway).

paths Option

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

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

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:

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

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

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.):

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

📚 Tutorial

https://github.com/erbelion/tutorial-vite-plugin-laravel-purgecss

👉 See Also

版本与发布记录

@erbelion/vite-plugin-laravel-purgecss 共发布 33 个版本,首次发布于 2022/10/10;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.4.8latest2026/04/286 个月前
0.4.72026/02/119 个月前
0.4.62026/02/119 个月前
0.4.52026/02/119 个月前
0.4.42025/11/1611 个月前
0.4.32025/11/1611 个月前

关于 @erbelion/vite-plugin-laravel-purgecss 的常见问题

@erbelion/vite-plugin-laravel-purgecss 是什么?

A Vite plugin that integrates PurgeCSS with Laravel template assets.

如何安装 @erbelion/vite-plugin-laravel-purgecss?

在项目目录运行 npm install @erbelion/vite-plugin-laravel-purgecss,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vite(>=3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@erbelion/vite-plugin-laravel-purgecss 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@erbelion/vite-plugin-laravel-purgecss 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@erbelion/vite-plugin-laravel-purgecss 可以商用吗?

@erbelion/vite-plugin-laravel-purgecss 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@erbelion/vite-plugin-laravel-purgecss 的下载量有多少?

根据 npm 官方下载统计,@erbelion/vite-plugin-laravel-purgecss 在 2026/10/14 – 2026/11/12 这 30 天内被下载 6,336 次,日均约 211 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@erbelion/vite-plugin-laravel-purgecss 还在维护吗?

最新版本 0.4.8 发布于 2026/04/28(6 个月前);至今共发布 33 个版本,其中过去 12 个月发布了 6 个;首次发布于 2022/10/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。