$ cnpm install @csstools/postcss-image-set-function
PostCSS plugin for polyfilling image-set CSS function.
.foo {
align-items: center;
background-image: image-set(url(img/test.png) 1x,
url(img/test-2x.png) 2x,
url(my-img-print.png) 600dpi);
color: black;
}
/* becomes */
.foo {
align-items: center;
background-image: url(img/test.png);
}
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
.foo {
background-image: url(img/test-2x.png);
}
}
@media (-webkit-min-device-pixel-ratio: 6.25), (min-resolution: 600dpi) {
.foo {
background-image: url(my-img-print.png);
}
}
.foo {
color: black;
}
❗️ Resolution media query is supported only by IE9+.
npm i postcss-image-set-polyfill -D
var postcssImageSet = require('postcss-image-set-polyfill');
postcss([postcssImageSet]).process(YOUR_CSS, /* options */);
See PostCSS docs for examples for your environment.
The preserve option determines whether the original image-set() rule should
or not should not be removed. By default, the original image-set() rule is
removed.
postcssImageSet({ preserve: true })
.foo {
align-items: center;
background-image: image-set(url(img/test.png) 1x,
url(img/test-2x.png) 2x);
color: black;
}
/* becomes */
.foo {
align-items: center;
background-image: url(img/test.png);
}
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
.foo {
background-image: url(img/test-2x.png);
}
}
.foo {
background-image: image-set(url(img/test.png) 1x,
url(img/test-2x.png) 2x);
color: black;
}
If you use autoprefixer, place this plugin before it to prevent styles duplication.
Copyright 2013 - present © cnpmjs.org | Home |