Skip to content

Instantly share code, notes, and snippets.

@samoshkin
Created January 19, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samoshkin/e715bc191b644da7279ec6c92de89a66 to your computer and use it in GitHub Desktop.
Save samoshkin/e715bc191b644da7279ec6c92de89a66 to your computer and use it in GitHub Desktop.
Create common,vendor and several entry point bundles using systemjs-builder
let Builder = require('systemjs-builder');
let fs = require('fs');
let mapValues = require('lodash/mapValues');
let config = {
baseURL: '.',
map: {
'vendor': 'lib/vendor'
}
};
let b = new Builder('.');
b.config(config);
(async function(){
try {
let vendor = 'output/vendor.js';
let common = 'output/common.js';
let entry1 = 'output/entry1.js';
let entry2 = 'output/entry2.js';
let bundles = {
[vendor]: await b.bundle(`(entry1.js + entry2.js) & (lib/vendor/*.js)`, vendor),
[common]: await b.bundle(`(entry1.js & entry2.js) - ${vendor}`, common),
[entry1]: await b.bundle(`entry1.js - ${common} - ${vendor}`, entry1),
[entry2]: await b.bundle(`entry2.js - ${common} - ${vendor}`, entry2)
};
Object.assign(config, {
bundles: mapValues(bundles, v => v.modules)
});
console.log(JSON.stringify(config.bundles, null, 2));
fs.writeFileSync(
'output/system-config.js',
`System.config(${JSON.stringify(config, null, 2)})`);
console.log('Build complete');
}catch(e){
console.log('Build error', e);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment