systemjs-builder
Advanced tools
Comparing version 0.10.0 to 0.10.1
@@ -116,2 +116,9 @@ var traceur = require('traceur'); | ||
// pending Babel v5, we need to manually map the helpers | ||
if (options.optional && options.optional.indexOf('runtime') != -1) | ||
load.deps.forEach(function(dep) { | ||
if (dep.match(/^babel-runtime/)) | ||
output.code = output.code.replace(dep, load.depMap[dep]); | ||
}); | ||
return Promise.resolve({ | ||
@@ -118,0 +125,0 @@ source: output.code, |
@@ -18,3 +18,2 @@ var Promise = require('rsvp').Promise; | ||
outFile: outFile, | ||
runtime: false, | ||
normalize: true, | ||
@@ -57,3 +56,3 @@ | ||
pluginLoader.instantiate = function(load) { | ||
return pluginInstantiate.call(this, load) | ||
return Promise.resolve(pluginInstantiate.call(this, load)) | ||
.then(function(instantiateResult) { | ||
@@ -60,0 +59,0 @@ if (global.System !== loader) |
{ | ||
"name": "systemjs-builder", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "SystemJS Build Tool", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"source-map": "^0.4.1", | ||
"systemjs": "^0.16.0", | ||
"systemjs": "^0.16.3", | ||
"traceur": "0.0.87", | ||
@@ -18,3 +18,3 @@ "uglify-js": "^2.4.17" | ||
"babel-core": "^4.7.16", | ||
"es6-module-loader": "^0.16.0", | ||
"es6-module-loader": "^0.16.1", | ||
"mocha": "~2.0.0", | ||
@@ -21,0 +21,0 @@ "chai": "^1.10.0", |
105
README.md
SystemJS Build Tool [![Build Status][travis-image]][travis-url] | ||
=== | ||
_For upgrading to 0.10, [see the release notes here](https://github.com/systemjs/builder/releases/tag/0.10.0)._ | ||
Provides a single-file build for SystemJS of mixed-dependency module trees. | ||
Builds ES6 into ES3, CommonJS, AMD and globals into a single file in a way that supports the CSP SystemJS loader | ||
Builds ES6 into ES5, CommonJS, AMD and globals into a single file in a way that supports the CSP SystemJS loader | ||
as well as circular references. | ||
@@ -40,2 +42,4 @@ | ||
Ensure that the transpiler is installed separately (`npm install babel` here). | ||
```javascript | ||
@@ -46,3 +50,3 @@ var path = require("path"); | ||
var builder = new Builder({ | ||
baseURL: path.resolve('some/folder'), | ||
baseURL: 'file:' + path.resolve('some/folder'), | ||
@@ -95,5 +99,4 @@ // any map config | ||
### Self-Executing (SFX) Bundles | ||
### SFX Bundles | ||
To make a bundle that is independent of the SystemJS loader entirely, we can make SFX bundles: | ||
@@ -105,8 +108,14 @@ | ||
This bundle file can then be included with a `<script>` tag, and no other dependencies (apart from Traceur or Babel runtime if needed) would need to be included in the page. | ||
This bundle file can then be included with a `<script>` tag, and no other dependencies would need to be included in the page. | ||
SFX bundles do not support custom exclusions and inclusions as there is no loader registry. | ||
By default, Traceur or Babel runtime are automatically included in the SFX bundle if needed. To exclude the Babel or Traceur runtime set the `runtime` build option to false: | ||
Rather, if it is needed to have globals like `jQuery` not included, as they will be separate globals, set up a wrapper module something like: | ||
```javascript | ||
builder.buildSFX('myModule', 'outfile.js', { runtime: false }); | ||
``` | ||
#### Adapter Modules | ||
To have globals like `jQuery` not included, and included in a separate script tag, set up an adapter module something like: | ||
jquery.js | ||
@@ -131,8 +140,27 @@ ```javascript | ||
If you want minification without mangling, you can set the config like this: | ||
#### Minification Options | ||
* `mangle`, defaults to true. | ||
* `globalDefs`, object allowing for global definition assignments for dead code removal. | ||
```javascript | ||
builder.build('myModule', 'outfile.js', { minify: true, mangle: false }); | ||
builder.build('myModule', 'outfile.js', { minify: true, mangle: false, globalDefs: { DEBUG: false } }); | ||
``` | ||
### In-Memory Builds | ||
Leave out the `outFile` option to run an in-memory build: | ||
```javascript | ||
builder.build('myModule', { minify: true }).then(function(output) { | ||
output.source; // generated bundle source | ||
output.sourceMap; // generated bundle source map | ||
output.modules; // array of module names defined in the bundle | ||
}); | ||
``` | ||
The `output` object above is provided for all builds, including when `outFile` is set. | ||
`output.modules` can be used to directly populate SystemJS bundles configuration. | ||
### Ignore Resources | ||
@@ -149,14 +177,12 @@ | ||
### Advanced build | ||
### Bundle Arithmetic | ||
The trace trees can be adjusted between tracing and building allowing for custom build layer creation. | ||
Both `builder.build` and `builder.buildSFX` support bundle arithmetic expressions. This allows for the easy construction of custom bundles. | ||
Some simple trace tree operators are provided for subtraction addition and intersection. | ||
There is also a `builder.trace` and `builder.buildTree` for building direct trace tree objects. | ||
Tree operations include `addTrees`, `subtractTrees`, `intersectTrees` and `extractTree`. | ||
#### Example - Arithmetic Expressions | ||
#### Example - Exclusion | ||
In this example we build all our application code in `app/` excluding the tree `app/corelibs`: | ||
In this example we build `app/core` excluding `app/corelibs`: | ||
```javascript | ||
@@ -171,19 +197,8 @@ var Builder = require('systemjs-builder'); | ||
builder.trace('app/main') | ||
.then(function(appTrace) { | ||
return builder.trace('app/corelibs') | ||
.then(function(coreTrace) { | ||
return Builder.subtractTrees(appTrace.tree, coreTrace.tree); | ||
}); | ||
}) | ||
.then(function(appMinusCoreTree) { | ||
return builder.buildTree(appMinusCoreTree, 'output-file.js', { minify: true, sourceMaps: true }); | ||
}); | ||
builder.build('app/* - app/corelibs', 'output-file.js', { minify: true, sourceMaps: true }); | ||
``` | ||
#### Example - Common Libraries | ||
#### Example - Trace Builds | ||
In this example we build `app/first` and `app/second` creating a separate `app/shared` library: | ||
In this example we build `app/first` and `app/second` into two separate bundles, while creating a separate shared bundle: | ||
@@ -197,24 +212,10 @@ ```javascript | ||
var firstTree, secondTree, commonTree; | ||
builder.trace('app/first') | ||
.then(function(trace) { | ||
firstTree = trace.tree; | ||
return builder.trace('app/second'); | ||
}) | ||
.then(function(trace) { | ||
secondTree = trace.tree; | ||
commonTree = Builder.intersectTrees(firstTree, secondTree); | ||
firstTree = Builder.subtractTrees(firstTree, commonTree); | ||
secondTree = Builder.subtractTrees(secondTree, commonTree); | ||
return builder.buildTree(firstTree, 'first-bundle.js'); | ||
}) | ||
.then(function() { | ||
return builder.buildTree(secondTree, 'second-bundle.js'); | ||
}) | ||
.then(function() { | ||
return builder.buildTree(commonTree, 'shared-bundle.js'); | ||
Promise.all([builder.trace('app/first'), builder.trace('app/second')]) | ||
.then(function(trees) { | ||
var commonTree = builder.intersectTrees(trees[0], trees[1]); | ||
return Promise.all([ | ||
builder.buildTree(commonTree, 'shared-bundle.js') | ||
builder.buildTree(builder.subtractTrees(trees[0], commonTree), 'first-bundle.js'), | ||
builder.buildTree(builder.subtractTrees(trees[1], commonTree), 'second-bundle.js') | ||
]); | ||
}); | ||
@@ -221,0 +222,0 @@ ``` |
var Builder = require('../index'); | ||
var builder = new Builder('./test/fixtures/test-tree.config.js'); | ||
builder.config({ transpiler: 'babel' }); | ||
suite('Bundle Expressions', function() { | ||
@@ -5,0 +7,0 @@ test('Addition', function(done) { |
System.config({ | ||
baseURL: './test/fixtures/test-tree/', | ||
paths: { | ||
'jquery-cdn': 'https://code.jquery.com/jquery-2.1.1.min.js', | ||
'babel': '../../../node_modules/babel-core/browser.js', | ||
'babel-helpers': '../../../node_modules/babel-core/external-helpers.js', | ||
'traceur': '../../../node_modules/traceur/bin/traceur.js', | ||
'traceur-runtime': '../../../node_modules/traceur/bin/traceur-runtime.js' | ||
}, | ||
map: { | ||
@@ -11,0 +4,0 @@ 'jquery-cdn': '@empty' |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
102645
223
1
2321
Updatedsystemjs@^0.16.3