Skip to content

Instantly share code, notes, and snippets.

@kmaraz
Created September 8, 2020 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmaraz/dde04554e701b5741a106502a30b93b7 to your computer and use it in GitHub Desktop.
Save kmaraz/dde04554e701b5741a106502a30b93b7 to your computer and use it in GitHub Desktop.
Our great function
/**
* 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