Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global libraries with system.js

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?

like image 754
coquin Avatar asked Mar 17 '23 12:03

coquin


1 Answers

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

or

System.set('angular', System.newModule({
    "default": window.angular
}));
like image 144
Sub Avatar answered Mar 22 '23 23:03

Sub