SystemJS: loading build file

故事扮演 提交于 2019-12-01 14:47:32

When you transpile to a single file, it produces a file in a special format called 'bundle'. When you import it, all the modules in it are loaded and registered in SystemJS, but nothing is executed. So, after the bundle is loaded, you need to add a second import in index.html that will actually start your application, like this:

    System.import('app/dist/build.js').then(function() {
        System.import('main');
    })
    .catch(function(err){ console.error(err); });

This code uses explicit path to load a bundle: app/dist/build.js, and then loads a module named main because that name must match exactly the module name as it is given in define call in the bundle. So, nothing in this code refers to the angular-boot or app package as it's defined in systemjs.config.js, so nothing needs to be changed in that file.

It's also possible to load a bundle with ordinary <script> tag, then you will need only single System.import('main') after that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!