postcss-colors-only
v1.1.4
Published
PostCSS plugin to remove all rules except those which contain one or more colors.
Maintainers
Readme
PostCSS Colors Only
PostCSS plugin to remove all rules except those which contain one or more colors.
This tool is useful if you are re-skinning a site with a new color scheme and need a starting point for a new stylesheet.
.foo {
color: red;
border: 1px solid #ab560f;
font-size: 16px;
background-image: linear-gradient(to-bottom, red, blue);
}
.bar {
color: rgba(0, 128, 255, 0.5);
}
.baz {
display: block;
}.foo {
color: red;
border-color: #ab560f;
background-image: linear-gradient(to-bottom, red, blue);
}
.bar {
color: rgba(0, 128, 255, 0.5);
}This plugin will remove any CSS rules that do not contain a color (named, hex, rgb, rgba, hsl, or hsla) value. It looks at the following CSS properties for colors:
colorbackgroundbackground-colorbackground-imageborderborder-topborder-rightborder-bottomborder-leftborder-colorborder-top-colorborder-right-colorborder-bottom-colorborder-left-coloroutlineoutline-colortext-decorationtext-decoration-colortext-shadowbox-shadowfillstrokestop-colorflood-colorlighting-color
The following CSS properties will be transformed, leaving only the color part of the declaration:
background→background-colorborder→border-colorborder-top→border-top-colorborder-right→border-right-colorborder-bottom→border-bottom-colorborder-left→border-left-coloroutline→outline-colortext-decoration→text-decoration-color
Installation
npm install postcss-colors-onlyUsage
var postcss = require('postcss');
var colorsOnly = require('postcss-colors-only');
var options = {
withoutGrey: false, // set to true to remove rules that only have grey colors
withoutMonochrome: false, // set to true to remove rules that only have grey, black, or white colors
inverse: false, // set to true to remove colors from rules
};
postcss()
.use(colorsOnly(options))
.process('a { color: red; background: #FF0 url(foo.jpg); font-size: 12px; }')
.css;
//=> 'a { color: red; background-color: #FF0; }'CLI
This plugin is also part of a standalone command line tool. See css-color-extractor-cli.
License
Copyright (c) 2015 Rob Sanchez
Licensed under the MIT License.
