Last active
December 3, 2016 05:07
-
-
Save prashaantt/257cf2a8cf4e8ee7f847 to your computer and use it in GitHub Desktop.
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
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