2017-04-04 86 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