像以前的beta聚合模块一样打包并运行Angular2 RC.0

Nic*_*aux 5 javascript angular

自从我升级到Angular2 RC.0以来,所有模块现在都被单独加载(应用程序加载时有600个HTTP请求),这个模块非常长并且几乎无法使用.beta17一次加载所有模块(或者每个核心至少有一个文件,http,rxjs ......).

我已经关注了beta和RC的官方快速入门指南.

你能告诉我如何使用与beta相同的机制或新的机制是什么使用RC.0的聚合模块?

Nic*_*aux 0

通过使用 @A-Hsiao 的答案并添加 rxjs 依赖项,我成功地将所有 js 文件合并到一个缩小的文件中。必须执行以下节点脚本。

    var Builder = require('systemjs-builder');

var packages = {
    'rxjs': {main: 'Rx.js'}
};
var packageNames = [
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/http',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router-deprecated',
];

packageNames.forEach(function (pkgName) {
    packages[pkgName] = {main: 'index.js'};
});
packageNames.push('rxjs');
var builder = new Builder({
    baseURL: '/node_modules',
    defaultJSExtensions: true,
    packages: packages
});

packageNames.forEach(function (pkgName) {
    builder.bundle(pkgName, 'build/assets/' + pkgName + '.js')
        .then(function () {
            console.log(pkgName + ' Build complete');
        })
        .catch(function (err) {
            console.log(pkgName + ' Build error');
            console.log(err);
        });
});
Run Code Online (Sandbox Code Playgroud)

所有生成的文件都可以合并和缩小。然后必须在捆绑文件后导入以下 systemjs.config.js。

(function (global) {
    var map = {
        'app': 'app'
    };

    var packages = {
        'app': {main: 'main.js'},
        'rxjs': {main: 'Rx.js'}
    };

    var packageNames = [
        '@angular/common',
        '@angular/compiler',
        '@angular/core',
        '@angular/http',
        '@angular/platform-browser',
        '@angular/platform-browser-dynamic',
        '@angular/router-deprecated'
    ];

    packageNames.forEach(function (pkgName) {
        packages[pkgName] = {main: 'index.js'};
    });

    var config = {
        map: map,
        packages: packages,
        defaultJSExtensions: true
    };

    if (global.filterSystemConfig) {
        global.filterSystemConfig(config);
    }

    System.config(config);

})(this);
Run Code Online (Sandbox Code Playgroud)