A PostCSS plugin to filter declarations by property names
var fs = require('fs');
var postcss = require('postcss');
var filterDeclarations = require('postcss-filter-declarations');
postcss()
.use(filterDeclarations({props: ['display', 'color']}))
.process(fs.readFileSync('path/to/css/file'))
.css;
.menubar {
display: block;
position: fixed;
color: gray;
}
@media print {
h1 {
font-size: 16px;
}
a {
color: blue;
}
}
↓
.menubar {
display: block;
color: gray;
}
@media print {
h1 {
}
a {
color: blue;
}
}
npm install postcss-filter-declarations
var filterDeclarations = require('postcss-filter-declarations');
options: Object
Return: Function
(alias: options.props)
Type: Stirng
or Array
of String
Default: []
Removes all CSS declarations except for the proerties specified by this option.
postcss()
.use(filterDeclarations({
props: 'color'
}))
.process('a {color: red;} b {background: blue;}')
.css; //=> 'a {color: red;} b {}'
Type: Boolean
Defult: false
true
inverts the filtering result.
postcss()
.use(filterDeclarations({
props: 'color',
exclude: true
}))
.process('a {color: red;} b {background: blue;}')
.css; //=> 'a {} b {background: blue;}'
Copyright (c) 2014 - 2019 Shinnosuke Watanabe
Licensed under the MIT License.