Skip to content

postcss/postcss-filter-plugins

Repository files navigation

postcss-filter-plugins

GitHub package.json version npm downloads GitHub Workflow Status License

Exclude/warn on duplicated PostCSS plugins.

Install

npm install postcss-filter-plugins

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.

const counter = () => ({
  postcssPlugin: "counter",
  Once(css) {
    css.walkDecls("foo", (decl) => {
      let value = parseInt(decl.value, 10);
      value += 1;
      decl.value = String(value);
    });
  },
});
counter.postcss = true;

const css = "h1 { foo: 1 }";
const out = postcss([filter(), counter(), counter()]).process(css).css;

console.log(out);
// => h1 { foo: 2 }
// Note 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.

postcss([ 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.

postcss([ 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.

postcss([ 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.

postcss([ 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

About

Exclude/warn on duplicated PostCSS plugins.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors