Skip to content

Instantly share code, notes, and snippets.

@kmaraz
Created September 8, 2020 00:19
Show Gist options
  • 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