Skip to content

Latest commit

 

History

History
79 lines (67 loc) · 2.04 KB

api.md

File metadata and controls

79 lines (67 loc) · 2.04 KB
title lang meta
Programmatic API | PurgeCSS
en-US
name content
description
PurgeCSS is a tool for removing CSS that you're not actually using in your project. You can use its programmatic API to use it as part of your development workflow.
itemprop content
description
PurgeCSS is a tool for removing CSS that you're not actually using in your project. You can use its programmatic API to use it as part of your development workflow.
property content
og:url
property content
og:site_name
purgecss.com
property content
og:image
property content
og:locale
en_US
property content
og:title
Remove unused CSS - PurgeCSS
property content
og:description
PurgeCSS is a tool for removing CSS that you're not actually using in your project. You can use its programmatic API to use it as part of your development workflow.

Programmatic API

Start by installing PurgeCSS as a dev dependency.

npm i -D purgecss

You can now use PurgeCSS inside a JavaScript file.

In the following examples, the options passed to PurgeCSS are the same as the ones here. The result purgecssResult is an array of an object containing the name of the files with the purged CSS.

Usage

ES Module Import Syntax

import { PurgeCSS } from 'purgecss'
const purgeCSSResult = await new PurgeCSS().purge({
  content: ['**/*.html'],
  css: ['**/*.css']
})

CommonJS Syntax

const { PurgeCSS } = require('purgecss')
const purgeCSSResult = await new PurgeCSS().purge({
  content: ['**/*.html'],
  css: ['**/*.css']
})

The format of purgeCSSResult is

[
    {
        file: 'main.css',
        css: '/* purged css for main.css */'
    },
    {
        file: 'animate.css',
        css: '/* purged css for animate.css */'
    }
]

The type of the result is

interface ResultPurge {
  css: string;
  file?: string;
  rejected?: string[];
  rejectedCss?: string;
}