Browse Source

add exlclude option to ignore some files

https://github.com/evrone/postcss-px-to-viewport/issues/11
pull/14/head
msidolphin 7 years ago
committed by GitHub
parent
commit
07c63a6622
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      index.js

20
index.js

@ -32,11 +32,17 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {
css.walkDecls(function (decl, i) {
// Add exlclude option to ignore some files like 'node_modules'
if (opts.exclude) {
if (Object.prototype.toString.call(opts.exclude) !== '[object RegExp]') {
throw new Error('options.exclude should be RegExp!')
if (Object.prototype.toString.call(opts.exclude) === '[object RegExp]') {
if (!handleExclude(opts.exclude, decl.source.input.file)) return;
} else if (Object.prototype.toString.call(opts.exclude) === '[object Array]') {
for (let i = 0; i < opts.exclude.length; ++i) {
if (!handleExclude(opts.exclude[i], decl.source.input.file)) return;
}
} else {
throw new Error('options.exclude should be RegExp or Array!');
}
if (decl.source.input.file.match(opts.exclude) !== null) return;
}
// This should be the fastest test and will remove most declarations
@ -59,6 +65,14 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {
};
});
function handleExclude (reg, file) {
if (Object.prototype.toString.call(reg) !== '[object RegExp]') {
throw new Error('options.exclude should be RegExp!');
}
if (file.match(reg) !== null) return false;
return true;
}
function getUnit(prop, opts) {
return prop.indexOf('font') === -1 ? opts.viewportUnit : opts.fontViewportUnit;
}

Loading…
Cancel
Save