postcss-discard

2.0.0 • Public • Published

PostCSS Discard Build Status

PostCSS plugin to discard rules by selector, RegExp, or @type. Also usable to generate a diff from two stylesheets

Usage

const discard = require('postcss-discard');
postcss([discard(options)]);

See PostCSS docs for examples for your environment.

Options

Name Type Description
atrule String, RegExp, Function Match atrule like @font-face
rule String, RegExp, Function Match rule like .big-background-image {...}
decl String, RegExp, Function Match declarations
css String CSS String or path to file containing css

You can also pass a filter function for any of the supported types. The function is invoked with two arguments (node, value).

  • node The currently processed AST node generated by postcss.
  • value Current value.

Return true if the element should be discarded.

Examples

Diffing stylesheets

postcss(discard({css: 'STYLES TO BE REMOVED'})).process('ORIGINAL CSS').css;

Discard by specifying rules

.bg {
  width: 100%;
  height: 100%;
  background-image: url('some/big/image.png');
}

@font-face {
  font-family: 'My awesome font';
}

@media print {
  ...;
}
postcss([
  discard({
    atrule: ['@font-face', /print/],
  }),
]);
.bg {
  width: 100%;
  height: 100%;
}

Dependencies (4)

Dev Dependencies (4)

Package Sidebar

Install

npm i postcss-discard

Weekly Downloads

24,260

Version

2.0.0

License

MIT

Unpacked Size

8.65 kB

Total Files

5

Last publish

Collaborators

  • bezoerb