Introduction | Purgecss (2024)

PurgeCSS is a tool to remove unused CSS. It can be used as part of your development workflow. PurgeCSS comes with a JavaScript API, a CLI, and plugins for popular build tools.

Here are a couple of ways to use PurgeCSS:

CLI

You can install the CLI in two ways. By installing PurgeCSS globally or using npx.

Install globally

npm i -g purgecss

Run PurgeCSS from the terminal:

purgecss --css <css> --content <content> [option]

Use npx

npx allows you to run the CLI locally without installing the package globally.

Install PurgeCSS as a dev dependency:

npm i -D purgecss

Run PurgeCSS from the terminal:

npx purgecss --css <css> --content <content> [option]

JavaScript API

Install PurgeCSS as a dev dependency:

npm i -D purgecss

ES6 with import

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

ES5 with require

var Purgecss = require('purgecss')var purgecss = new Purgecss({ content: ['**/*.html'], css: ['**/*.css']})var purgecssResult = purgecss.purge()

Webpack

Install the Webpack plugin as a dev dependency:

npm i -D purgecss-webpack-plugin

Use the plugin in your Webpack config:

const path = require('path')const glob = require('glob')const ExtractTextPlugin = require('extract-text-webpack-plugin')const PurgecssPlugin = require('purgecss-webpack-plugin')const PATHS = { src: path.join(__dirname, 'src')}module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.join(__dirname, 'dist') }, module: { rules: [ { test: /\.css$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader?sourceMap' }) } ] }, plugins: [ new ExtractTextPlugin('[name].css?[hash]'), new PurgecssPlugin({ paths: glob.sync(`${PATHS.src}/*`) }) ]}

PostCSS

Install the PostCSS plugin as a dev dependency:

npm i -D @fullhuman/postcss-purgecss

Use the plugin in your PostCSS config:

const purgecss = require('@fullhuman/postcss-purgecss')module.exports = { plugins: [ purgecss({ content: ['./**/*.html'] }) ]}

Gulp

Install the Gulp plugin as a dev dependency:

npm i -D gulp-purgecss

Use the plugin in your Gulpfile:

const gulp = require('gulp')const purgecss = require('gulp-purgecss')gulp.task('purgecss', () => { return gulp .src('src/**/*.css') .pipe( purgecss({ content: ['src/**/*.html'] }) ) .pipe(gulp.dest('build/css'))})

Grunt

Install the Grunt plugin as a dev dependency:

npm i -D grunt-purgecss

Use the plugin in your Gruntfile:

module.exports = grunt => { grunt.initConfig({ purgecss: { options: { content: ['./src/**/*.html'] }, my_target: { files: { './dist/app.purged.css': './src/app.css' } } } }) grunt.loadNpmTasks('grunt-purgecss') grunt.registerTask('default', ['purgecss'])}

Rollup

Install the Rollup plugin as a dev dependency:

npm i -D rollup-plugin-purgecss

Use the plugin in your Rollup config:

import { rollup } from 'rollup'import purgecss from 'rollup-plugin-purgecss'rollup({ entry: 'main.js', plugins: [ purgecss({ content: ['index.html'] }) ]})
Introduction | Purgecss (2024)
Top Articles
Tips for Selling Your Airbnb Property for Top Dollar
Investment Style: Meaning, Factors, Different Styles
Scheelzien, volwassenen - Alrijne Ziekenhuis
Thor Majestic 23A Floor Plan
Is Sam's Club Plus worth it? What to know about the premium warehouse membership before you sign up
Dr Doe's Chemistry Quiz Answer Key
Craigslist In South Carolina - Craigslist Near You
Puretalkusa.com/Amac
Amateur Lesbian Spanking
Strange World Showtimes Near Amc Braintree 10
Fire Rescue 1 Login
Our Facility
Miami Valley Hospital Central Scheduling
Guardians Of The Galaxy Vol 3 Full Movie 123Movies
Degreeworks Sbu
Classroom 6x: A Game Changer In The Educational Landscape
Five Day National Weather Forecast
Google Flights Missoula
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
Buying Cars from Craigslist: Tips for a Safe and Smart Purchase
Happy Homebodies Breakup
Lexus Credit Card Login
Helpers Needed At Once Bug Fables
Mta Bus Forums
2011 Hyundai Sonata 2 4 Serpentine Belt Diagram
Maine Racer Swap And Sell
Emuaid Max First Aid Ointment 2 Ounce Fake Review Analysis
Best Laundry Mat Near Me
Issue Monday, September 23, 2024
Netherforged Lavaproof Boots
The 38 Best Restaurants in Montreal
Naya Padkar Newspaper Today
1v1.LOL Game [Unblocked] | Play Online
Saybyebugs At Walmart
Blackwolf Run Pro Shop
Ross Dress For Less Hiring Near Me
Skyward Marshfield
Ig Weekend Dow
Lamont Mortuary Globe Az
Differential Diagnosis
Alpha Labs Male Enhancement – Complete Reviews And Guide
Avance Primary Care Morrisville
Silicone Spray Advance Auto
Unit 11 Homework 3 Area Of Composite Figures
RubberDucks Front Office
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
Theatervoorstellingen in Nieuwegein, het complete aanbod.
FactoryEye | Enabling data-driven smart manufacturing
Food and Water Safety During Power Outages and Floods
Gear Bicycle Sales Butler Pa
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 5738

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.