The options available in the PurgeCSS configuration are also available in the Webpack plugin (except css and content).
paths
With the Webpack plugin, you can specify content that should be analyzed by PurgeCSS with an array of filenames. The files can be HTML, Pug, Blade, etc. You can also use a module like glob or glob-all to easily get a list of files.
constPurgecssPlugin=require('purgecss-webpack-plugin')constglob=require('glob')constPATHS= { src:path.join(__dirname,'src')}// In the webpack configurationnewPurgecssPlugin({ paths:glob.sync(`${PATHS.src}/*`)})
If you want to regenerate the paths list on every compilation (e.g. with --watch), then you can also pass a function:
Similar as for the paths option, you also can define functions for the these options:
functioncollectWhitelist() {// do something to collect the whitelistreturn ['whitelisted'];}functioncollectWhitelistPatterns() {// do something to collect the whitelistreturn [/^whitelisted-/];}// In the Webpack configurationnewPurgecssPlugin({ whitelist: collectWhitelist, whitelistPatterns: collectWhitelistPatterns})