Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package and run Angular2 RC.0 like the previous beta aggregated module

Since I upgraded to Angular2 RC.0, all the modules are now loaded individually (600 HTTP requests on the application loading) which is very long and almost unusable. The beta17 loads all the modules at once (or at least one file for each core, http, rxjs...).

I have followed the official quickstart guide for beta and RC.

Could you tell me how to use the same mechanism as the beta or what the new mechanism is to use aggregate modules with the RC.0 ?

like image 733
Nicolas Henneaux Avatar asked Oct 19 '22 10:10

Nicolas Henneaux


1 Answers

I have the same issue, and resolved by 'systemjs-builder'. but havn't test detailly. for you as a reference. https://github.com/A-hsien/Angular2-systemjs-builder

thx for comment from @Gaurav.

following code will package '@angular' by each folder under '@angular'. just save them to a whateverthename.js file.

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

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

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

var builder = new Builder({
  baseURL: '/node_modules',
  defaultJSExtensions: true,
  packages: packages
});

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

then execute the command node whateverthename.js. modeues will be build to assets folder.

like image 156
A-Hsien Avatar answered Oct 21 '22 03:10

A-Hsien