Config Map包名称前缀为namespace +冒号

时间:2017-04-04 20:51:02

标签: node.js angular requirejs systemjs

我在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'
    },

我的问题是:map似乎使用了配置路径的别名,如' npm',并以冒号":"为后缀,然后将此字符串添加到包文件中名称,如示例中的npm:@ angular / forms / bundles / forms.umd.js。

但是我查看了SystemJS的config API和RequireJS的config,但我没有找到任何有关此用法的文档。有没有人曾经为此工作,并可以为此提供一些有用的链接或文档。提前谢谢。

1 个答案:

答案 0 :(得分: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

  2. npm:@angular/core/bundles/core.umd.js已映射到node_modules/@angular/core/bundles/core.umd.jsnpm:替换为node_modules/,感谢paths选项。

  3. 您可以使用除npm:以外的任何其他字符串,我的工作方式相同。