Mapping already loaded JavaScript

25 views
Skip to first unread message

achim.has...@gmail.com

unread,
May 2, 2016, 3:46:48 AM5/2/16
to SystemJS
I have a 3rd party TypeScript library that loads an external JavaScript library using SystemJS. In my case it is loading moment.js, a popular date library.

I already bundle moment.js in a combined script called scripts.js which I load before SystemJS with a simple <script>. This has all my legacy external JS libraries.

Now SystemJS errors out when it tries to load "moment". I somehow need to map this request in SystemJS to "null" so it doesn't do anything because it's already loaded. How can that be achieved?

I'm also not sure about the namespace, would SystemJS do anything to moment when importing it or just load it?

Guy Bedford

unread,
May 2, 2016, 10:53:31 AM5/2/16
to achim.has...@gmail.com, SystemJS
You can do this empty mapping by `System.config({ map: { 'moment': '@empty' } })` and then just use the global value for `moment` directly in the modules.

Alternatively create an alias module `moment.js` that contains `module.exports = window.moment` say. Then create a map to that alias module - `map: { 'moment': 'path/to/moment.js' }`.

--
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