## Configuration API ### Configuration Options * [baseURL](#baseurl) * [bundles](#bundles) * [depCache](#depcache) * [map](#map) * [meta](#meta) * [packages](#packages) * [packageConfigPaths](#packageconfigpaths) * [pluginFirst](#pluginfirst) * [paths](#paths) * [transpiler](#transpiler) * [warnings](#warnings) #### baseURL Type: `String` Default: Environment baseURI The _baseURL_ provides a mechanism for knowing where to load plain modules names from, regardless of which parent module they are being loaded from. For example: ```javascript SystemJS.config({ baseURL: '/modules' }); System.import('x'); ``` will load `x` from `/modules/x`. Plain modules are module names like the above, which do not begin with `/`, `./`, `../` and are not absolute URLs. Relative URLs are still resolved relative to the parent module, or for a top-level import, relative to the environment baseURI. #### bundles Type: `Object` Default: `{}` Bundles allow a collection of modules to be downloaded together as a package whenever any module from that collection is requested. Useful for splitting an application into sub-modules for production. Use with the [SystemJS Builder](https://github.com/systemjs/builder). ```javascript SystemJS.config({ bundles: { bundleA: ['dependencyA', 'dependencyB'] } }); ``` In the above any require to `dependencyA` or `dependencyB` will first trigger a `SystemJS.import('bundleA')` before proceeding with the load of `dependencyA` or `dependencyB`. It is an alternative to including a script tag for a bundle in the page, useful for bundles that load dynamically where we want to trigger the bundle load automatically only when needed. The bundle itself is a module which contains named System.register and define calls as an output of the builder. The dependency names the bundles config lists should be the same names that are explicitly defined in the bundle. #### depCache Type: `Object` Default: `{}` The `depCache` option is an alternative to bundling, providing a solution to the latency issue of progressively loading dependencies. When a module specified in depCache is loaded, asynchronous loading of its pre-cached dependency list begins in parallel. ```javascript SystemJS.config({ depCache: { moduleA: ['moduleB'], // moduleA depends on moduleB moduleB: ['moduleC'] // moduleB depends on moduleC } }); // when we do this import, depCache knows we also need moduleB and moduleC, // it then directly requests those modules as well as soon as we request moduleA SystemJS.import('moduleA') ``` Over HTTP/2 this approach may be preferable as it allows files to be individually cached in the browser meaning bundle optimizations are no longer a concern. #### map Type: `Object` Default: `{}` The map option is similar to paths, but acts very early in the normalization process. It allows you to map a module alias to a location or package: ```javascript SystemJS.config({ map: { jquery: '//code.jquery.com/jquery-2.1.4.min.js' } }); ``` ```javascript import $ from 'jquery'; ``` Map configuration only applies to plain names, as described in the baseURL section above, although maps can contain `/` separators. In addition, a map also applies to any subpaths, making it suitable for package folders as well: ```javascript SystemJS.config({ map: { package: 'local/package' } }); ``` ```javascript // loads /local/package/path.js SystemJS.import('package/path.js'); ``` Contexual map configuration allows mappings to only apply to certain packages: ```javascript SystemJS.config({ map: { 'local/package': { x: 'vendor/x.js' }, 'another/package': { x: 'vendor/y.js' } } }); ``` Means that `import "x"` within the file `local/package/index.js` will load from `vendor/x.js`, while the same import in `another/package/file.js` will load `vendor/y.js`. This type of configuration enables multi-version support. Contextual map configuration is equivalent to the package map configuration. #### meta Type: `Object` Default: `{}` Module meta provides an API for SystemJS to understand how to load modules correctly. Meta is how we set the module format of a module, or know how to shim dependencies of a global script. ```javascript SystemJS.config({ meta: { // meaning [baseURL]/vendor/angular.js when no other rules are present // path is normalized using map and paths configuration 'vendor/angular.js': { format: 'global', // load this module as a global exports: 'angular', // the global property to take as the module value deps: [ // dependencies to load before this module 'jquery' ] } } }); ``` Wildcard meta is also supported and is additive from least to most specific match: ```javascript SystemJS.config({ meta: { '/vendor/*': { format: 'global' } } }); ``` * [`authorization`]: This can be a custom authorization header string for XHR requests made by SystemJS. * `crossOrigin`: When scripts are loaded from a different domain (e.g. CDN) the global error handler (`window.onerror`) has very limited information about errors to [prevent unintended leaking](https://developer.mozilla.org/en/docs/Web/API/GlobalEventHandlers/onerror#Notes). In order to mitigate this, the `