2017-04-04 50 views
1

我看到Angular2启动项目的System.Config.JS为例前缀配置地图包的名称,它下面喜欢:命名空间+冒号

(function (global) { 
System.config({ 
    paths: { 
     // paths serve as alias 
     'npm:': 'node_modules/' 
    }, 
    // map tells the System loader where to look for things 
    map: { 
     // our app is within the app folder 
     'app': 'app', 
     // angular bundles 
     '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
     '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
     '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
     '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
     '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
     '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
     '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
     '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 

     // other libraries 
     'rxjs': 'npm:rxjs', 
     'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js' 
    }, 

我的问题是:地图似乎采用的配置路径的别名,如“故宫',后缀为冒号“:”,然后将此字符串前置到包文件名,例如npm:@ angular/forms/bundles/forms.umd.js。

但是我抬头看了一下SystemJS的config API和RequireJS的config,但是我没有找到任何这种用法的文档。有没有人有过这方面的工作,并可以提供一些有用的链接或文件。先谢谢你。

回答

0

文档的相关部分是这样的:https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#paths

的医生说:

路径允许创建后map配置

这是Angular2配置是否适用映射。冒号“:”没有什么特别的含义,只是为了让它更加明显,所有的模块都来自npm

例如,当您导入模块@angular/core

  1. @angular/core映射到npm:@angular/core/bundles/core.umd.js感谢map选项。其中npm:替换node_modules/感谢paths选项

  2. npm:@angular/core/bundles/core.umd.js被映射到node_modules/@angular/core/bundles/core.umd.js

你可以使用除npm:以外的任何其他字符串,我会以同样的方式工作。

+0

哦,对了,我错过了“npm:”整个部分是一个配置路径散列表键,不仅仅是“npm”。谢谢你指给我。 – IcyBrk