Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlexxNica/b9a66683c4b8a93240531bb9b02d5003 to your computer and use it in GitHub Desktop.
Save AlexxNica/b9a66683c4b8a93240531bb9b02d5003 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.module || pkg['jsnext:main']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment