How to purgecss with wordpress ?
-
So I already made my custom theme, but my style.css is a bit bloated, because I copied from other sources. And I want to remove unused css with purgecss.
My theme structure
wp-content/themes/*.php
wp-content/themes/style.css
wp-content/themes/assets/*.js
wp-content/themes/assets/*.cssI just want to trim style.css
Inside folder assets only bootstrap css, I don’t know if purgecss can trim that or not.
I already installed purgecss in dev, here is my package.json"devDependencies": { "purgecss": "^4.0.3", "purgecss-with-wordpress": "^4.0.3" }From what I read in the documentation, I need to use configuration file, and use CLI to output the trimmed style.css
How to do that ? My current configuration at purgecss.config.jsimport PurgeCSS from 'purgecss' import purgecssWordpress from 'purgecss-with-wordpress' const purgeCSSResults = await new PurgeCSS().purge({ content: ['*.php'], css: ['style.css', 'assets/*.css'], safelist: purgecssWordpress.safelist, safelistPatterns: purgecssWordpress.safelistPatterns })Is that correct already ? So I just run purgecss –config ./purgecss.config.js ?
How to specify output ? I don’t want to overwrite the existing style.css
The topic ‘How to purgecss with wordpress ?’ is closed to new replies.