Get the selectors of a JS file.
This is an experimental js extractor for purgecss. It uses prepack to partially evaluate the javascript code.
npm i -D purgecss-from-js
import Purgecss from "purgecss"
import purgeHtml from "purgecss-from-js"
const purgeCss = new Purgecss({
content: ["**/*.html"],
css: ["**/*.css"],
extractors: [
{
extractor: purgeJs,
extensions: ["js"]
}
]
})
const result = purgecss.purge()
import purgeHtml from "purgecss-from-js"
import fs from "fs"
const htmlContent = fs.readFileSync("index.js")
const htmlSelectors = purgeHtml.extract(htmlContent)