@erbelion/vite-plugin-laravel-purgecss
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

vite-plugin-laravel-purgecss

Get package from npm Downloads Downloads views

A Vite plugin that integrates PurgeCSS with Laravel 11/10/9 template assets (currently updated to laravel/laravel@11.3.2).

It purges assets only in production mode (yarn build/npm run build).

📦 Installation

yarn

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

npm

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

🚀 Usage

Use plugin in your Vite config (vite.config.ts)

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

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

See more examples

🛠️ Options

Parameter Type Optional Description
paths string[] yes List of paths to be processed by PurgeCSS.
PurgeCSS Options Partial<UserDefinedOptions> yes PurgeCSS options (see docs).
templates string[] yes ❌ deprecated (see anyway).

paths option

If paths option isn't specified, it will default to: resources/{js,views}/**/*.{blade.php,svelte,vue,html}

All options

type Options = {
  
  // plugin options
  paths?: string[]
  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 + 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

vite-plugin-sveltekit-purgecss

Package Sidebar

Install

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

Weekly Downloads

430

Version

0.3.1

License

MIT

Unpacked Size

18.9 kB

Total Files

15

Last publish

Collaborators

  • erbelion