From d6b78f3f8fdeba7b93979ce2ed13ec989b611e5a Mon Sep 17 00:00:00 2001 From: "minjs.cn" Date: Thu, 17 Sep 2020 20:02:49 +0800 Subject: [PATCH] feature: add units to config --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d4e12fa..04e1a03 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const filterPropList = require("./lib/filter-prop-list"); const type = require("./lib/type"); const defaults = { + units: 'rem', rootValue: 16, unitPrecision: 5, selectorBlackList: [], @@ -47,7 +48,8 @@ module.exports = postcss.plugin("postcss-pxtorem", options => { const pxReplace = createPxReplace( rootValue, opts.unitPrecision, - opts.minPixelValue + opts.minPixelValue, + opts.units ); css.walkDecls((decl, i) => { @@ -100,13 +102,13 @@ function convertLegacyOptions(options) { }); } -function createPxReplace(rootValue, unitPrecision, minPixelValue) { +function createPxReplace(rootValue, unitPrecision, minPixelValue, units) { return (m, $1) => { if (!$1) return m; const pixels = parseFloat($1); if (pixels < minPixelValue) return m; const fixedVal = toFixed(pixels / rootValue, unitPrecision); - return fixedVal === 0 ? "0" : fixedVal + "rem"; + return fixedVal === 0 ? "0" : fixedVal + units; }; }