FullHuman / postcss-purgecss

PostCSS plugin for purgecss
MIT License
91 stars 5 forks source link

Asynchronously set options #56

Open garygreen opened 4 years ago

garygreen commented 4 years ago

Currently you can only supply options to the plugin with an object. It would be useful if you could also pass a function and call the given setPurgeCssOptions callback to set the options.

require('@fullhuman/postcss-purgecss')(function(setPurgeCssOptions) {
    exec_command('git ls-files js/*.js', function(gitFiles) {
        setPurgeCssOptions({
            content: toArray(gitFiles),
        });
    });
});

Use case

Our particular use case is we want to build up a list of content files for PurgeCSS to consider but only if it's part of git/version control - as we are calling an async process we need to build the options up asynchronously. It's possible we could do this by creating our own plugin and then hooking into that, but I just thought I'd make this suggestion as it would provide an easier API.