Skip to content

Instantly share code, notes, and snippets.

@frnwtr
Last active May 7, 2021 02:04
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frnwtr/5647673bb15ca8893642469d3b400cba to your computer and use it in GitHub Desktop.
Save frnwtr/5647673bb15ca8893642469d3b400cba to your computer and use it in GitHub Desktop.
const WordpressPurgeCSS = {
whitelist: [
"rtl",
"home",
"blog",
"archive",
"date",
"error404",
"logged-in",
"admin-bar",
"no-customize-support",
"custom-background",
"wp-custom-logo"
],
whitelistPatterns: [
/^search(-.*)?$/,
/^(.*)-template(-.*)?$/,
/^(.*)?-?single(-.*)?$/,
/^postid-(.*)?$/,
/^attachmentid-(.*)?$/,
/^attachment(-.*)?$/,
/^page(-.*)?$/,
/^(post-type-)?archive(-.*)?$/,
/^author(-.*)?$/,
/^category(-.*)?$/,
/^tag(-.*)?$/,
/^tax-(.*)?$/,
/^term-(.*)?$/,
/^(.*)?-?paged(-.*)?$/
]
};
@adampatterson
Copy link

I gave this a try and my SASS compiles, but a lot of the Gutenberg/Media alignment is missing, Do you have any suggestions?

I can manually add them I suppose.

@bfiessinger
Copy link

@adampatterson if this is still a concern I built a similar whitelist for Gutenberg.
Check it out at https://www.npmjs.com/package/purgecss-with-gutenberg

@adampatterson
Copy link

Thanks @bfiessinger, I will try it out. I ended up hunting through the code for a lot of the elements.

@ankurdhiman89
Copy link

ankurdhiman89 commented May 18, 2020

Please give me some link from where i get the information where i add this file in theme file or in root file
please tell me where i add this code {
import Purgecss from 'purgecss'
import purgecssWordpress from 'purgecss-with-wordpress'
const purgeCss = new Purgecss({
content: ['/*.html'],
css: ['
/*.css'],
whitelist: purgecssWordpress.whitelist,
whitelistPatterns: purgecssWordpress.whitelistPatterns
})
const result = purgecss.purge()
}
how i run this code
please help me?
thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment