Skip to content

Instantly share code, notes, and snippets.

@izumskee
Created February 23, 2017 21:58
Show Gist options
  • Save izumskee/89b0a342d8c2b05018fc7a234b019a4c to your computer and use it in GitHub Desktop.
Save izumskee/89b0a342d8c2b05018fc7a234b019a4c to your computer and use it in GitHub Desktop.
const MODULE_DIR = /(.*([\/\\]node_modules|\.\.)[\/\\](@[^\/\\]+[\/\\])?[^\/\\]+)([\/\\].*)?$/g;
{
loader: 'babel-loader',
test: /\.jsx?$/,
include(filepath) {
if (filepath.split(/[/\\]/).indexOf('node_modules')===-1) return true;
let pkg, manifest = path.resolve(filepath.replace(MODULE_DIR, '$1'), 'package.json');
try { pkg = JSON.parse(fs.readFileSync(manifest)); } catch (e) {}
return !!(pkg.modules || pkg['jsnext:main']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment