2020-10-20 05:15:30 +00:00

2 lines
1.0 KiB
JavaScript
Executable File

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("postcss")),s=require("purgecss"),o=e(s);const r=t.plugin("postcss-plugin-purgecss",(function(e){return async function(t,r){const n=new o,c={...s.defaultOptions,...e};e&&"function"==typeof e.contentFunction&&(c.content=e.contentFunction(t.source&&t.source.input.file||"")),n.options=c;const{content:i,extractors:u}=c,a=i.filter(e=>"string"==typeof e),p=i.filter(e=>"object"==typeof e),l=await n.extractSelectorsFromFiles(a,u),f=await n.extractSelectorsFromString(p,u),m=s.mergeExtractorSelectors(l,f);n.walkThroughCSS(t,m),n.options.fontFace&&n.removeUnusedFontFaces(),n.options.keyframes&&n.removeUnusedKeyframes(),n.options.variables&&n.removeUnusedCSSVariables(),n.options.rejected&&n.selectorsRemoved.size>0&&(r.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${n.selectorsRemoved.size} selectors:\n ${Array.from(n.selectorsRemoved).map(e=>e.trim()).join("\n ")}`}),n.selectorsRemoved.clear())}}));module.exports=r;