Skip to content

Instantly share code, notes, and snippets.

@markstickley
Last active August 29, 2015 14:16
Show Gist options
  • Save markstickley/c1bc6663cbe36bc0d46e to your computer and use it in GitHub Desktop.
Save markstickley/c1bc6663cbe36bc0d46e to your computer and use it in GitHub Desktop.
systemjs-builder optimizeBuild function spec
var entryPoints = {
entryPoint1Name: 'path/to/entryPoint',
entryPoint2Name: 'path/to/anoher/entryPoint',
entryPoint3Name: 'path/to/aThird/entryPoint'
};
/*
Note: entryPoints can also be an array if you are happy to use default bundle names
E.g.
var entryPoints = [
'path/to/entryPoint',
'path/to/anoher/entryPoint',
'path/to/aThird/entryPoint'
];
*/
builder.optimizeBuild(entryPoints, require('custom-optimizer'), {
// builder-specific options:
outPath: 'out/folder', // optional, if not set returns source as memory compilation
sourceMaps: true,
uglify: true,
minify: true,
// etc other options
// custom configuration options not handled by builder but needed by the optimizer get passed through:
entrypointPriorities: {},
// etc...
}).
then(function(optimizedData) {
console.dir(optimizedData);
/*
{
bundles: [
{
name: 'bundle1Name',
entryPoint: 'path/to/bundle1/entryPoint', // optional - just for reference, some bundles may not be for a specific entry point and the bundle can still be created without this
modules: ['path/to/dependency1','path/to/dependency2'], // modules in this bundle
source: '...' // provided if in memory mode and no outPath given
},
...
],
config: {
depCache: {
'path/to/bundle1/entryPoint': ['path/to/dependency1','path/to/dependency2']
},
bundles: {
'out/folder/bundle1Name': ['path/to/bundle1/entryPoint','path/to/dependency1','path/to/dependency2']
}
}
}
*/
});
/**
* Optional, user-defined function to process the tree data generated from the entry points
* @param {{String|String[]}|[String|String[]]} entryPoints Object or array of entry points (strings or arrays of strings)
* @param {Object} trace Full trace data mapping to the entry points
* @param {Object} optimizationOptions Custom variables that can be required or optional for this optimization function
* @return {Promise|{bundleName:Tree, ...} Promise to be resolved with an object of Trees or
* an object of Trees, with each tree representing a bundle to be written.
*/
function optimizationFunction(entryPoints, trace, optimizationOptions) {
// <clever manuipulation of trees happens here>
return {
bundles: [{
name: 'bundle-1', // name of the bundle in the outpath
entryPoint: 'path/to/entryPoint', // entry point this bundle is for
modules: ['path/to/module', 'path/to/anotherModules'], // modules in this bundle
tree: {}, // The tree object generated by builder functions
},
...
],
config: {
depCache: {
...
},
bundles: {
...
}
}
};
// Note the bundle names don't have to be used in the returned data structure if the optimization
// algorithm calls for a different practice. Also, if no names are provided default names should be
// used here (bundle0, bundle1, bundle2, etc).
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment