Created
September 8, 2020 00:19
-
-
Save kmaraz/dde04554e701b5741a106502a30b93b7 to your computer and use it in GitHub Desktop.
Our great function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Thank you very much @jh3141 | |
* @see https://github.com/webpack/webpack/issues/2031#issuecomment-317589620 | |
*/ | |
const excludeNodeModulesExcept = function (modules) { | |
var pathSep = path.sep; | |
if (pathSep == '\\') | |
// must be quoted for use in a regexp: | |
pathSep = '\\\\'; | |
var moduleRegExps = modules.map(function (modName) { | |
return new RegExp('node_modules' + pathSep + modName); | |
}); | |
return function (modulePath) { | |
if (/node_modules/.test(modulePath)) { | |
for (var i = 0; i < moduleRegExps.length; i++) | |
if (moduleRegExps[i].test(modulePath)) return false; | |
return true; | |
} | |
return false; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment