2017-02-28 39 views
1

我是angular2的新手,我想知道systemjs.config.js文件中存在的所有對象的用法。angularj中的systemjs.config.js

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: 'dist', 
     main: 'main.js', 

     // 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', 
     'primeng':     'npm:primeng'  
    }, 
    // packages tells the System loader how to load when no filename and/or no extension 
    packages: { 
     app: { main: 'main.js', defaultExtension: 'js' }, 
     api: { defaultExtension: 'js' }, 
     rxjs: {defaultExtension: 'js'}, 
     'node_modules/primeng': { 
      format: 'cjs', 
      defaultExtension: 'js' 
      } 
     } 

}); 

例如上面粘貼的碼具有類似路徑其可以被用來指定別名,以相同的方式對象我想知道使用地圖和地圖的所有內部對象,所以上。

回答

3

好了,首先你說不出哪裏NPM包的位置,通常在根,因此:

paths: { 
    // paths serve as alias 
    'npm:': 'node_modules/' 
} 

然後你給別名(快捷方式名稱)的包,你將使用中,這種情況下角和一些第三方庫像rxjs,...

map: { 
     // our app is within the app folder 
     app: 'dist', 
     main: 'main.js', 

     // 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', 
     'primeng':     'npm:primeng'  
    } 

因此,而不是當您導入庫中輸入完整的路徑(如「故宮:@角/芯/包/ core.umd.js '),你只需要導入你給它的別名('@ angular/core')。在導入別名時,您確定您正在導入正確的庫。

'npm:'在圖書館的完整路徑前面,指的是你在上面啓動的路徑'npm'。

+0

對於遲到的回覆感到抱歉,您還可以更新systemjs.config.js中包對象的詳細信息....謝謝 –

+0

像更改路徑一樣嗎?是的你可以。 – TanguyB

+0

我想問的是,你能否詳細解釋包裏的所有對象的包對象和目的 –

相關問題