Skip to content

Instantly share code, notes, and snippets.

@prashaantt
Last active December 3, 2016 05:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashaantt/257cf2a8cf4e8ee7f847 to your computer and use it in GitHub Desktop.
Save prashaantt/257cf2a8cf4e8ee7f847 to your computer and use it in GitHub Desktop.
const Fs = require('fs');
const Path = require('path');
const files = [];
const nodeModules = {};
const getFilesAndSubdirectories = (dir) => {
Fs.readdirSync(dir)
.forEach((item) => {
const fqn = `${dir}/${item}`;
const fqFileName = fqn.replace('./node_modules/', '');
const stat = Fs.statSync(fqn);
if (stat.isDirectory()) {
files.push(fqFileName);
getFilesAndSubdirectories(fqn);
}
else if (stat.isFile() && Path.extname(fqn).substring(1) === 'js') {
files.push(fqFileName.replace('.js', ''));
}
});
};
getFilesAndSubdirectories('./node_modules');
files.forEach((file) => {
nodeModules[file] = `commonjs ${file}`;
});
// exclude all node modules in config
config.externals = nodeModules;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment