postcss-px2rpx
Version:
PostCSS plugin for converting px values (adapting to iPhone 6) to Weapp's rpx values.
22 lines (17 loc) • 558 B
JavaScript
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-px2rpx', function (opts) {
opts = opts || {};
var timesBigger = opts.times || 2;
// Work with options here
return function (root) {
// Transform CSS AST here
root.walkDecls(decl => {
var val = decl.value;
if (val.indexOf('px') > -1) {
decl.value = val.replace(/(\d+)px/g, function (match, num) {
return num * timesBigger + 'rpx';
});
}
});
};
});