Skip to content

Instantly share code, notes, and snippets.

@cdaringe
Created December 29, 2015 17:36
Show Gist options
  • Save cdaringe/d5111497e54eff9be9c2 to your computer and use it in GitHub Desktop.
Save cdaringe/d5111497e54eff9be9c2 to your computer and use it in GitHub Desktop.
webpack-external-regex-use-node-require.js
var getExternals = function() {
var internals = [/react/]; // assert that all of these entries remain in webpack bundle
var externals = [];
var externalsHash = {
fs: 'commonjs fs',
ipc: 'commonjs ipc',
remote: 'commonjs remote',
path: 'commonjs path',
config: 'commonjs config',
os: 'commonjs os',
};
// add all packages to externals that aren't otherwise explicity internal
Object.keys(require('./package.json').dependencies).forEach(function(packageName) {
var isInternal = internals.some(function(internal) { return packageName.match(internal) });
if (isInternal) {
return;
}
externalsHash[packageName] = 'commonjs ' + packageName
});
externals.push(externalsHash);
externals.push(/app\/common\/.*js/); // don't pack anything with /app/common/ in the path (risky, but probably ok)
externals.push(/common\/boot\.js/);
externals.push(/app\/main\/.*js/);
return externals;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment