diff --git a/README_CN.md b/README_CN.md index 158f2e4..ecb2cb2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -176,6 +176,21 @@ module.exports = { } } } +``` + + `viewportWidth` as function +```js +module.exports = { + plugins: { + // ... + 'postcss-px-to-viewport': { + // options + viewportWidth({ file }) { + return file.indexOf('vant') !== -1 ? 375 : 750 + }, + } + } +} ``` #### 直接在gulp中使用,添加gulp-postcss diff --git a/index.js b/index.js index 6419322..1dfb2f0 100755 --- a/index.js +++ b/index.js @@ -118,7 +118,10 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) { size = opts.landscapeWidth; } else { unit = getUnit(decl.prop, opts); - size = opts.viewportWidth; + size = typeof opts.viewportWidth === "function" + ? opts.viewportWidth(css.source.input) + : opts.viewportWidth; + } var value = decl.value.replace(pxRegex, createPxReplace(opts, unit, size));