Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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']);
}
}
@lukeed

This comment has been minimized.

Copy link

commented Feb 25, 2017

Line 10 should be pkg.module.

@NekR

This comment has been minimized.

Copy link

commented Apr 22, 2017

return !!pkg && !!(pkg.module || pkg['jsnext:main']);

@DamianFekete

This comment has been minimized.

Copy link

commented Aug 10, 2018

Thanks.
Don't forget to import fs (const fs = require('fs');)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.