javascript - angular2中systemjs的问题
黄舟
黄舟 2017-04-11 09:02:49
[JavaScript讨论组]

网上没搜寻到什么systemjs的资料

如下代码,
有几个问题:
1.

"materialize": "npm:angular2-materialize",
"angular2-materialize": "npm:angular2-materialize",           

这两句什么意思?,后面的路径是一样的,前面的名字起什么作用?

2.

 packages: {
            app: {
                main: './main.js',
                // defaultExtension: 'js'
            },

package是干嘛的,注释说是当没有文件名的时候告诉加载器如何加载?这句话怎么理解?

全部代码:

       
/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    System.config({
        defaultJSExtensions: true,
        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',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
            'angular2-cookie': 'npm:angular2-cookie',

            //material
            "materialize-css": "npm:materialize-css",
            "materialize": "npm:angular2-materialize",
            "angular2-materialize": "npm:angular2-materialize",

            // 'ng2-image-lazy-load': 'node_modules/ng2-image-lazy-load'
            'angular2-infinite-scroll': 'npm:angular2-infinite-scroll'
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                // defaultExtension: 'js'
            },
            rxjs: {
                // defaultExtension: 'js'
            },
            'angular-in-memory-web-api': {
                main: './index.js',
                // defaultExtension: 'js'
            },
            "materialize-css": {
                // "format": "global",
                main: "dist/js/materialize",
                // "defaultExtension": "js"
            },
            "materialize": {
                main: "dist/materialize-directive",
                // "defaultExtension": "js"
            },
            'angular2-cookie': {
                main: './core.js',
                // defaultExtension: 'js'
            },
            'angular2-infinite-scroll': {
                main: './angular2-infinite-scroll.js',
                // defaultExtension: 'js'
            },
        }
    });
})(this);
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
黄舟

SystemJS配置文件, 主要配置着需要由SystemJS加载的由Typescript编译器所编译的模块。
对于那些单独的JS文件,允许通过配置一个映射map和包入口(packages)来加载。
比如你需要加载模块 app/test , SystemJS会按下面的步骤来执行:

  1. 看有没有事先在systemJS中注册:System.register('app/test', ...)

  2. 如果没有,则就会去配置文件查找是否存在app映射(map), 是否有存在app packages 入口,如果找到了,则会建立请求来加载对应的模块: http://localhost:3000/app/tes...
    如果你的app映射是map: { app: dist }

这个时候request 就会是 http://localhost:3000/dist/te...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号