Map multiple (sub) modules to single file?

38 views
Skip to first unread message

tobias....@googlemail.com

unread,
May 9, 2016, 5:21:24 AM5/9/16
to SystemJS
I wrote a library in TypesSript and compiled it to a single JavaScript file in the System/Register format, which now contains multiple modules.

Modules:
'mylib'
'mylib/collection'
'mylib/ui/control'
'...'

JavaScript:
...
System.register("mylib/collection", ["mylib/base", "mylib/exception", "mylib/event"], function(exports_25, context_25) {
...
}
System.register("mylib/ui/control", ["mylib/ui/core", "mylib/ui/container"], function(exports_28, context_28) {
...
}
...

In a second project i want to use that library. So i could do:

import * as mylib from 'mylib';
import Button = mylib.ui.control.Button;
import List = mylib.collection.List;

But i would like to write the following instead:

import {Button} from 'form/ui/control';
import {List} from 'form/collection';

But the latter won't work, because SystemJS tries to load the module 'mylib/ui/control' from //mylib/ui/control.js instead of //mylib.js. How do i tell SystemJS that it should look up this sub modules inside mylib.js?

Guy Bedford

unread,
May 15, 2016, 7:35:58 PM5/15/16
to tobias....@googlemail.com, SystemJS
If you load the built file with a script tag in the page before loading your own project code, then those module will be defined into the SystemJS module registry already and there won't be any spearate file requests for them.

Alternatively you can use bundles configuration to load the bundle on-demand.

--
You received this message because you are subscribed to the Google Groups "SystemJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to systemjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages