64f99f1d77dcc93d2174bf16d8e0cfbc584cd090e187daf5e3925bb595f104378fe0f32e43f9f7ae9b024c00db51e1b291e3e3e621b4afc39c29b7d2e55b40 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # [postcss][postcss]-filter-plugins [![Build Status](https://travis-ci.org/postcss/postcss-filter-plugins.svg?branch=master)][ci]
  2. > Exclude/warn on duplicated PostCSS plugins.
  3. ## Install
  4. With [npm](https://npmjs.org/package/postcss-filter-plugins) do:
  5. ```console
  6. $ npm install postcss-filter-plugins --save
  7. ```
  8. ## Example
  9. Note that this plugin does not actually transform your CSS; instead, it ensures
  10. that plugins in the PostCSS instance are not duplicated. It is intended to be
  11. used by plugin packs such as [cssnano] or [cssnext].
  12. ```js
  13. var counter = postcss.plugin('counter', function () {
  14. return function (css) {
  15. css.eachDecl('foo', function (decl) {
  16. let value = parseInt(decl.value, 10);
  17. value += 1;
  18. decl.value = String(value);
  19. });
  20. }
  21. });
  22. var css = 'h1 { foo: 1 }';
  23. var out = postcss([
  24. filter(),
  25. counter(),
  26. counter()
  27. ]).process(css).css;
  28. console.log(out);
  29. // => h1 { foo: 2 }
  30. // Note that you will get a PostCSS warning in the message registry
  31. ```
  32. ## API
  33. ### filterPlugins([options])
  34. #### options
  35. ##### direction
  36. Type: `string`
  37. Default: `'both'`
  38. Pass `'forward'`, `'backward'`, or `'both'` to customise the direction in which the
  39. plugin will look in the plugins array. See the [tests] for examples on how this
  40. works.
  41. ```js
  42. postcss([ filter({
  43. direction: 'forward'
  44. }) ]).process(css).css);
  45. ```
  46. ##### exclude
  47. Type: `array`
  48. Default: `[] (empty)`
  49. Plugins that should be excluded from the filter. Pass an array of plugin names.
  50. ```js
  51. postcss([ filter({
  52. exclude: ['postcss-cssstats']
  53. }) ]).process(css).css);
  54. ```
  55. ##### silent
  56. Type: `boolean`
  57. Default: `false`
  58. Set this to true to disable the plugin from emitting any PostCSS warnings.
  59. ```js
  60. postcss([ filter({
  61. silent: true
  62. }) ]).process(css).css);
  63. ```
  64. ##### template
  65. Type: `function`
  66. Default: `format function`
  67. This function will be passed each PostCSS plugin object. You are expected to
  68. return a string from each call, which is then used to warn the user about her
  69. duplicated plugins.
  70. ```js
  71. postcss([ filter({
  72. template: function (plugin) {
  73. return 'Duplicate plugin found: ' + plugin.postcssPlugin;
  74. }
  75. }) ]).process(css).css);
  76. ```
  77. ## Usage
  78. See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
  79. examples for your environment.
  80. ## Contributors
  81. Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
  82. <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
  83. | [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) [📖](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) 👀 [⚠️](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/157534?v=3" width="100px;"/><br /><sub>Maxime Thirouin</sub>](https://moox.io/)<br />[📖](https://github.com/postcss/postcss-filter-plugins/commits?author=MoOx) | [<img src="https://avatars.githubusercontent.com/u/373545?v=3" width="100px;"/><br /><sub>Andreas Lind</sub>](https://github.com/papandreou)<br />[💻](https://github.com/postcss/postcss-filter-plugins/commits?author=papandreou) |
  84. | :---: | :---: | :---: |
  85. <!-- ALL-CONTRIBUTORS-LIST:END -->
  86. This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
  87. Contributions of any kind welcome!
  88. ## License
  89. MIT © [Ben Briggs](http://beneb.info)
  90. [ci]: https://travis-ci.org/postcss/postcss-filter-plugins
  91. [cssnano]: http://cssnano.co
  92. [cssnext]: http://cssnext.io
  93. [postcss]: https://github.com/postcss/postcss
  94. [tests]: src/__tests__