From 18c40e9288910622e101dc9f6e747b71978041a3 Mon Sep 17 00:00:00 2001 From: Breathe <15983966644@qq.com> Date: Sun, 28 Nov 2021 15:53:15 +0800 Subject: [PATCH] Solve a problem: postcss-px-to-viewport: postcss.plugin was deprecated. --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 6419322..6662a7e 100755 --- a/index.js +++ b/index.js @@ -17,6 +17,8 @@ var defaults = { minPixelValue: 1, mediaQuery: false, replace: true, + exclude: undefined, + include: undefined, landscape: false, landscapeUnit: 'vw', landscapeWidth: 568 @@ -25,7 +27,7 @@ var defaults = { var ignoreNextComment = 'px-to-viewport-ignore-next'; var ignorePrevComment = 'px-to-viewport-ignore'; -module.exports = postcss.plugin('postcss-px-to-viewport', function (options) { +module.exports = (options = {}) => { var opts = objectAssign({}, defaults, options); checkRegExpOrArray(opts, 'exclude'); @@ -142,7 +144,7 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) { css.append(landscapeRoot); } }; -}); +}; function getUnit(prop, opts) { return prop.indexOf('font') === -1 ? opts.viewportUnit : opts.fontViewportUnit; @@ -158,10 +160,6 @@ function createPxReplace(opts, viewportUnit, viewportSize) { }; } -function error(decl, message) { - throw decl.error(message, { plugin: 'postcss-px-to-viewport' }); -} - function checkRegExpOrArray(options, optionName) { var option = options[optionName]; if (!option) return; @@ -176,7 +174,7 @@ function checkRegExpOrArray(options, optionName) { } if (!bad) return; } - throw new Error('options.' + optionName + ' should be RegExp or Array of RegExp.'); + throw new Error('options.' + optionName + ' type is' + Object.prototype.toString.call(option) + ', should be RegExp or Array of RegExp.'); } function toFixed(number, precision) { @@ -193,6 +191,13 @@ function blacklistedSelector(blacklist, selector) { }); } +function isExclude(reg, file) { + if (Object.prototype.toString.call(reg) !== '[object RegExp]') { + throw new Error('options.exclude should be RegExp.'); + } + return file.match(reg) !== null; +} + function declarationExists(decls, prop, value) { return decls.some(function (decl) { return (decl.prop === prop && decl.value === value);