postcss/postcss-filter-plugins

Name: postcss-filter-plugins

Owner: PostCSS

Description: Exclude/warn on duplicated PostCSS plugins.

Created: 2015-07-20 09:35:20.0

Updated: 2018-05-22 14:48:22.0

Pushed: 2018-05-22 14:48:20.0

Homepage: null

Size: 20

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

postcss-filter-plugins Build Status

Exclude/warn on duplicated PostCSS plugins.

Install

With npm do:

m install postcss-filter-plugins --save
Example

Note that this plugin does not actually transform your CSS; instead, it ensures that plugins in the PostCSS instance are not duplicated. It is intended to be used by plugin packs such as cssnano or cssnext.

counter = postcss.plugin('counter', function () {
return function (css) {
    css.eachDecl('foo', function (decl) {
        let value = parseInt(decl.value, 10);
        value += 1;
        decl.value = String(value);
    });
}


css = 'h1 { foo: 1 }';
out = postcss([
filter(),
counter(),
counter()
rocess(css).css;

ole.log(out);
> h1 { foo: 2 }
ote that you will get a PostCSS warning in the message registry
API
filterPlugins([options])
options direction

Type: string
Default: 'both'

Pass 'forward', 'backward', or 'both' to customise the direction in which the plugin will look in the plugins array. See the tests for examples on how this works.

css([ filter({
direction: 'forward'
).process(css).css);
exclude

Type: array
Default: [] (empty)

Plugins that should be excluded from the filter. Pass an array of plugin names.

css([ filter({
exclude: ['postcss-cssstats']
).process(css).css);
silent

Type: boolean
Default: false

Set this to true to disable the plugin from emitting any PostCSS warnings.

css([ filter({
silent: true
).process(css).css);
template

Type: function
Default: format function

This function will be passed each PostCSS plugin object. You are expected to return a string from each call, which is then used to warn the user about her duplicated plugins.

css([ filter({
template: function (plugin) {
    return 'Duplicate plugin found: ' + plugin.postcssPlugin;
}
).process(css).css);
Usage

See the PostCSS documentation for examples for your environment.

Contributors

Thanks goes to these wonderful people (emoji key):

|
Ben Briggs

? ? ? ?? |
Maxime Thirouin

? |
Andreas Lind

? |
Ryan Zimmerman

? |
James Hunt

? | | :—: | :—: | :—: | :—: | :—: |

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Ben Briggs


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.