5

I've got following set up in my index.html:

...
<script src="components/angular/angular.js"></script>

<script src="components/traceur/traceur.js"></script>
<script src="components/es6-module-loader/dist/es6-module-loader.src.js"></script>
<script src="components/system.js/dist/system.src.js"></script>

<script>
    System.baseURL = '/';
</script>

<script type="module">
    // Example
    import angular from 'angular';

    angular.module('myApp', [...]);
</script>

I'd like to load angular.js (and some other common libs) globally via script tag. But when I'm trying to use it in modules (in my case, es6-modules) system.js tries to load it via URL http://mysite/angular.js. It just doesn't see that I've already included it as global lib. I spent several hours figuring out how can I handle this, read system.js wiki on Github, but I'm still stuck with this.

Can anybody show how to configure system.js to work with global libs?

3
  • that goes against the whole point of using a module loader like System. If you really want to do this anyway, see: groups.google.com/forum/#!topic/systemjs/0_tuZW5s-JY Dec 31, 2014 at 0:03
  • What about big ones where you want to include them outside your SystemJS build: a) for build performance reasons, b) because other things rely on them being global. For example I want to use Three.js and also the Three.js 'extra' ColladaLoader which attaches itself to the global THREE object... Browserify-shim, for example, recommends doing that by including them with separate script tags. Apr 25, 2015 at 10:51
  • The SystemJS docs recommend adapter modules for globals via separate script includes (github.com/systemjs/builder#adapter-modules). However, this doesn't help if you're using a library that require()'s it via its npm name... :( Apr 25, 2015 at 14:27

1 Answer 1

7
System.registerDynamic('angular', [], false, function(require, exports, module) {
    module.exports = window.angular;
});

or

System.set('angular', System.newModule({
    "default": window.angular
}));
1
  • 1
    Thanks! This is what I was missing! The SystemJS documentation wasn't very helpful Nov 7, 2018 at 17:10

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.