Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Latest commit

 

History

History
201 lines (170 loc) · 7.67 KB

api.md

File metadata and controls

201 lines (170 loc) · 7.67 KB

API Documentation

Builder

new Builder(baseURL[, configFilePath])

baseURL: Sets the root for the loader
configFilePath: A systemjs config file conforming to the [systemjs config api] (https://github.com/systemjs/systemjs/blob/master/docs/config-api.md)

Example

new Builder('/scripts', 'config.js');

builder.config(config)

config: An object conforming to the [config api] (https://github.com/systemjs/systemjs/blob/master/docs/config-api.md)

Example

builder.config({
  map: {
    'a': 'b.js'
  }
});

builder.loadConfig(configFilePath)

configFilePath: A systemjs config file conforming to the [systemjs config api] (https://github.com/systemjs/systemjs/blob/master/docs/config-api.md)

Returns a promise which resolves when config has been loaded

Example

builder.loadConfig('config.js').then(() => {
});

builder.loadConfigSync(configFilePath)

Synchronous version of builder.loadConfig()

configFilePath: A systemjs config file conforming to the [systemjs config api] (https://github.com/systemjs/systemjs/blob/master/docs/config-api.md)

Example

builder.loadConfigSync('config.js');

builder.reset()

Reset the builder config to its initial state and clear loader registry. This will remove any registered modules, but will maintain the builder's compiled module cache. For efficiency, use builder.invalidate() to clear individual modules from the cache.

Example

builder.reset();

builder.invalidate(moduleName)

Removes a module from the loader cache

moduleName: The name of the module to invalidate, this can include wildcards

Returns the list of invalidated modules

Example

builder.invalidate("/jquery.js");
builder.invalidate("someLib/*");

builder.bundle(tree[, outfile][, options])

builder.bundle(expression[, outfile][, options])

builder.bundle(moduleNames[, outfile][, options])

Concatenate all modules in the tree or module tree expression and optionally write them out to a file

tree: A tree object as returned from builder.trace(), or one of the arithmetic functions
expression: A module tree expression
moduleNames: An array of exact, unnormalized module names
Important: The module names in expression or moduleNames should only be / separated (On Windows, do NOT use \ as your path separator for this argument). The module names are specified in URL space; in particular, they are not file-paths.
outfile: The file to write out the bundle to
options: Additional bundle options as outlined below

Returns a promise which resolves with the bundle content

Bundle options

minify: Minify source in bundle output (Default:true)
uglify: Options to pass to uglifyjs mangle: Allow the minifier to shorten non-public variable names (Default:false)
sourceMaps: Generate source maps for minified code (Default:false)
sourceMapContents: Include original source in the generated sourceMaps, this will generate a self-contained sourceMap which will not require the browser to load the original source file during debugging (Default:false)
lowResSourceMaps: When true, use line-number level source maps, when false, use character level source maps (Default:false)
globalName: When building a self-executing bundle, assign the bundle output to a global variable (Default:null)
globalDeps: When building a self-executing bundle, indicates external dependendencies available in the global context (Default:{})
fetch: Override the fetch function to retrieve module source manually (Default:undefined)
normalize: Rewrite required module names to their normalized names (Default:false)
anonymous: Compile modules as anonymous modules (Default:false)
systemGlobal: The global used to register compiled modules with systemjs (Default:'System')
format: Module format to compile modules to (Default:'umd')

Example

builder.bundle('moduleA.js', { minify:true }).then((bundle) => {
    //bundle contains source to moduleA.js + dependencies
});

builder.buildStatic(tree[, outfile][, options])

builder.buildStatic(expression[, outfile][, options])

Similar to builder.bundle() but builds a self-executing bundle

tree: A tree object as returned from builder.trace(), or one of the arithmetic functions
expression: A module tree expression
Important: The module names in expression or moduleNames should only be / separated (On Windows, do NOT use \ as your path separator for this argument). The module names are specified in URL space; in particular, they are not file-paths.
outfile: The file to write out the bundle to
options: Additional bundle options as outlined in builder.bundle()

Returns a promise which resolves with the bundle content

Example

builder.buildStatic('moduleA.js').then((sfxBundle) => {
    //sfxBundle contains source to moduleA.js + dependencies + self-executing intialization code
});

builder.trace(expression)

Creates the module tree object represented by expression

expression: A module tree expression
Important: The module names in expression should only be / separated (On Windows, do NOT use \ as your path separator for this argument). The module names are specified in URL space; in particular, they are not file-paths.

Returns a promise which resolves with the module tree

Example

builder.trace('moduleA.js').then((moduleTree) => {
});

builder.addTrees(firstTree, secondTree)

let moduleTree = builder.addTrees('moduleA.js', 'moduleB.js')

builder.subtractTrees(firstTree, secondTree)

let moduleTree = builder.subtractTrees('moduleA.js', 'moduleB.js');

builder.intersectTrees(firstTree, secondTree)

let moduleTree = builder.intersectTrees('moduleA.js', 'moduleB.js');

Module Tree Expressions

builder.buildStatic, builder.bundle and builder.trace accept module tree expressions

Module Tree

Represents moduleA and all of its dependencies

'moduleA.js'

Single Module

Represents moduleA only

'[moduleA.js]'

Addition

Represents a tree that combines moduleA, moduleB and their dependencies

'moduleA.js + moduleB.js'

Subtraction

Represents a tree that includes moduleA and its dependencies, excluding moduleB and its dependencies

'moduleA.js - moduleB.js'

Intersection

Represents the dependencies shared between moduleA and moduleB

'moduleA.js & moduleB.js'

Module Glob

Represents the combination of all modules in dirA and their dependencies

'dirA/*'

Parenthesis

Use parenthesis to group module tree operations

'(moduleA.js & moduleB.js) + moduleC.js'