diff --git a/buildPlugins/pxresize.js b/buildPlugins/pxresize.js index 55b98f4..0324c7c 100644 --- a/buildPlugins/pxresize.js +++ b/buildPlugins/pxresize.js @@ -6,24 +6,25 @@ let pxRegExp = /\b(\d+(\.\d+)?)px\b/; let pxGlobalRegExp = new RegExp(pxRegExp.source, 'g'); module.exports = postcss.plugin('postcss-px2rem', (option) => { - let opt = Object.assign({ - scale: 0.5, - ignore: [] - }, option) + let opt = Object.assign({ + scale: 0.5, + ignore: [] + }, option) - return (root, result) => { - const ignore = opt.ignore || [] - const file = result.opts.from - for (const ignoreElement of ignore) { - if (file.indexOf(ignoreElement) >= 0) return - } - root.walkDecls(function(decl) { - if (/px/.test(decl.value)) { - decl.value = decl.value.replace(pxGlobalRegExp, function(match, p1) { - return p1 * opt.scale + 'px' - }) - } + return (root, result) => { + const file = root.source.input.file + const ignore = opt.ignore || [] + for (const ignoreElement of ignore) { + const regExp = new RegExp(ignoreElement) + if (regExp.test(file)) return + } + root.walkDecls(function (decl) { + if (/px/.test(decl.value)) { + decl.value = decl.value.replace(pxGlobalRegExp, function (match, p1) { + return p1 * opt.scale + 'px' }) - result.root = root - }; + } + }) + result.root = root + }; }); diff --git a/pages/index.vue b/pages/index.vue index a54377a..b2f89ab 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -63,6 +63,7 @@ export default {