简体   繁体   English

JSPM与外部系统js文件捆绑在一起

[英]JSPM bundling with external system js file

I am loading my angular2 file as a System js module from CDN. 我正在从CDN加载我的angular2文件作为System js模块。

I have several files which imports various system js modules of angular2. 我有几个文件,它们导入了angular2的各种系统js模块。

Now I want to bundle my local javascript files using JSPM. 现在,我想使用JSPM捆绑本地javascript文件。 When I write the command 当我写命令时

  "jspm bundle app/main build.js"

JSPM fails. JSPM失败。 As JSPM is trying to find angular2 folder in my project. 由于JSPM试图在我的项目中找到angular2文件夹。 I know the reason that it checks the map defined in config.js. 我知道它检查config.js中定义的映射的原因。 But I want to know how to overcome this. 但是我想知道如何克服这个问题。 As I don't want to install angular2 file in my local project, and I definitely don't want to serve angular2 file from my server to client's browser, I want to use CDN. 由于我不想在本地项目中安装angular2文件,并且我绝对不想从服务器向客户端的浏览器提供angular2文件,因此我想使用CDN。

Please help. 请帮忙。

If you want to build and use CDN at the same time (because you configured some packages to load from CDN with SystemJS), you can build everything but the CDN packages. 如果你想建立,并在同一时间使用CDN(因为你配置一些软件包,从CDN加载具有 SystemJS),你可以建立的一切,但 CDN包。 For example: 例如:

jspm bundle app/main.js - angular2 - whatever + somethingelse main-bundle.js --inject

Otherwise, simplier, you can put the CDN links directly inside you index.html files and use SystemJS for local packages only. 否则,您可以将CDN链接直接放在index.html文件中,并将SystemJS仅用于本地软件包。

At last I found the answer to do this: 最后,我找到了执行此操作的答案:

System Js config option also takes a meta info. System Js config选项还需要一个元信息。 In this meta info we can write to ignore modules of SystemJs from being bundled. 在此元信息中,我们可以编写忽略SystemJ的模块的捆绑说明。 So lets say I am loading all the angular2 modules from cdn, importing them in local modules and then building it with systemJs or JSPM, then I must write the following in config.js(or inside System.config's options object): 所以可以说我要从CDN加载所有angular2模块,将它们导入本地模块,然后使用systemJs或JSPM进行构建,然后必须在config.js(或System.config的options对象中)中编写以下内容:

meta: {
        'angular2/*': {
            build: false
        },
        'rxjs/add/operator/map' : {
            build : false
        }
    }

This should be put in config.js by angular2 developers to explicitly tell systemJs to avoid looking for angular2 modules and rxjs modules while bundling the local modules. 应该由angular2开发人员将其放在config.js中,以明确告诉systemJs避免在绑定本地模块时查找angular2模块和rxjs模块。 This will provide you the opportunity to load angular2 and rxjs from cdn and consequently not include them in the map option of config.js. 这将为您提供从CDN加载angular2和rxjs的机会,因此不会将它们包括在config.js的map选项中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM