SystemJS
For upgrading to SystemJS 0.17, see the SystemJS 0.17 release upgrade notes for more information, or read the updated SystemJS Overview guide.
Universal dynamic module loader - loads ES6 modules, AMD, CommonJS and global scripts in the browser and NodeJS. Works with both Traceur and Babel.
- Loads any module format with exact circular reference and binding support.
- Loads ES6 modules compiled into the
System.registerbundle format for production, maintaining circular references support. - Supports RequireJS-style map, paths, bundles and global shims.
- Loader plugins allow loading assets through the module naming system such as CSS, JSON or images.
Built on top of the ES6 Module Loader polyfill coming to under 12KB minified and gzipped.
Runs in IE8+ and NodeJS.
For discussion, see the Google Group.
For a list of guides and tools, see the Third-Party Resources Wiki.
Documentation
- ES6 Modules Overview
- SystemJS Overview
- Config API
- Module Formats
- Production Workflows
- System API
- Creating Plugins
Basic Use
Browser
<script src="system.js"></script>
<script>
// set our baseURL reference path
System.config({
baseURL: '/app'
});
// loads /app/main.js
System.import('main.js');
</script>
To load ES6, locate traceur.js (eg from https://github.com/jmcriffey/bower-traceur) in the baseURL path and it will be loaded when needed.
For use with Babel, locate the browser.js file at babel.js in the baseURL and set:
<script>
System.transpiler = 'babel';
</script>
Alternatively a custom path to Babel or Traceur can also be set through paths:
System.config({
paths: {
traceur: 'path/to/traceur.js'
}
});
NodeJS
To load modules in NodeJS, install SystemJS with:
npm install systemjs traceur
(making sure to also install Traceur or Babel as needed, as they are not included as dependencies as of SystemJS 0.16)
We can then load modules equivalently to in the browser:
var System = require('systemjs');
/*
* Include
* System.transpiler = 'babel';
* to use Babel instead of Traceur
*/
// loads './app.js' from the current directory
System.import('./app').then(function(m) {
console.log(m);
});
Plugins
Supported loader plugins:
- CSS
System.import('my/file.css') - Image
System.import('some/image.png!image') - JSON
System.import('some/data.json') - Text
System.import('some/text.txt!text')
Additional Plugins:
- CoffeeScript
System.import('./test.coffee') - Jade
- JSX
System.import('template.jsx') - Markdown
System.import('app/some/project/README.md').then(function(html) {}) - WebFont
System.import('google Port Lligat Slab, Droid Sans !font') - Handlebars
System.import('template.hbs!') - Ember Handlebars
System.import('template.hbs!')
Read about using plugins here Read the guide here on creating plugins.
Running the tests
To install the dependencies correctly, run bower install from the root of the repo, then open test/test.html in a browser with a local server
or file access flags enabled.
License
MIT