diff --git a/src/index.js b/src/index.js index 2934b6c..b97abcb 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import transformSvg from './transformSvg'; import fileExistsWithCaseSync from './fileExistsWithCaseSync'; let ignoreRegex; +let includeRegex; export default declare(({ assertVersion, @@ -48,10 +49,17 @@ export default declare(({ if (typeof importPath !== 'string') { throw new TypeError('`applyPlugin` `importPath` must be a string'); } - const { ignorePattern, caseSensitive, filename: providedFilename } = state.opts; + const { ignorePattern, includePattern, caseSensitive, filename: providedFilename } = state.opts; const { file, filename } = state; let newPath; - if (ignorePattern) { + if (includePattern) { + // Only set the includeRegex once: + includeRegex = includeRegex || new RegExp(includePattern); + // Test if we should ignore this: + if (!includeRegex.test(importPath)) { + return; + } + } else if (ignorePattern) { // Only set the ignoreRegex once: ignoreRegex = ignoreRegex || new RegExp(ignorePattern); // Test if we should ignore this: