SystemJS:使用bundle-file更正System.import [英] SystemJS: Correct System.import with bundle-file

查看:82
本文介绍了SystemJS:使用bundle-file更正System.import的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的bundle out.js文件连接了main.js和app.component.js模块。现在我想使用SystemJS在index.html中导入这个out.js文件。实际上我想调用其中的主要(.js)模块。

My bundle out.js file concatenates a main.js and an app.component.js module. Now I want to import this out.js file in my index.html with SystemJS. Actually I want to "call" the main(.js)-module in it.

我现在想知道如何导入我的bundle文件的内部模块。是在内部System.import(bundle)中嵌套System.import(内部模块)的正确方法吗?实际上它是有效的,但我不确定这是否正常。

I am now wondering how to import the inner module of my bundle file. Is it the right way to nest a System.import (of inner module) in an outer System.import (of bundle)? Actually it is working but I'm not sure if this is fine.

index.html

index.html

<script type="text/javascript" src="lib/out.js"></script>

<script>
    System.config({
        packages: {
            lib: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
    System.import('lib/out')
            .then(function() { // ---Is this the way to do it?---
                System.import('/main');
            }, console.error.bind(console));
</script>

out.js

System.register('app.component', ['angular2/core'], function(exports_1, context_1) {
  var __moduleName = context_1 && context_1.id;
  ..
}};

System.register('main', ['angular2/platform/browser', './app.component'], function(exports_1, context_1) {
  var __moduleName = context_1 && context_1.id;    
  ..
}};


推荐答案

实际上你的 out.js 文件使用<$ c直接用名字注册你的模块$ c> System.register 。当您使用脚本标记添加此文件时,SystemJS中可以直接使用这些模块。

In fact your out.js file registers your modules directly with a name using System.register. So these modules are directly available within SystemJS when you add this file with a script tag.

<script src="lib/out.js"></script>

<script>
  System.import('main')
        .then(null, console.error.bind(console));
</script>

这篇关于SystemJS:使用bundle-file更正System.import的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆