systemjs / builder

SystemJS build tool
MIT License
465 stars 122 forks source link

Angular 2 bundle problem #662

Closed mii9000 closed 8 years ago

mii9000 commented 8 years ago

I create an Angular 2 bundle of my app using the following config.

System.config({
    defaultJSExtensions: true,
  map: {
    app: 'wwwroot/app/core',
    angular2: 'node_modules/angular2',
    rxjs: 'node_modules/rxjs',
    dragula: 'wwwroot/lib/dragula/dragula.min',
    'ng2-dragula/ng2-dragula': 'wwwroot/lib/dragula/ng2-dragula',
    'ng2-cookies/ng2-cookies': 'wwwroot/lib/ng2-cookies/ng2-cookies'
  },
  packages: {
    app: {
      defaultExtension: 'js',
      main: 'main.js'
    },
    angular2: {
      defaultExtension: 'js'
    },
    rxjs: {
      defaultExtension: 'js'
    }
  }
});

gulpfile.js

function getBuilder(configPath) {
    var builder = new SystemBuilder();
    return builder.loadConfig(configPath)
      .then(function () {
          return builder;
      });
}

gulp.task('bundle', function () {   
    return getBuilder('./system.config.js')
      .then(function (builder) {
          return builder.buildStatic('app', './bundledapp.js', { minify: true });
      });
});

If the { minify: true } then the bundle keeps on executing some code and overflows the tab before the browser/tab crashes. If I { minify: false } or { minify: true }, { mangle: false } then the bundle runs file as expected. What could be the reason for this? I need to mangle so that the bundle size can go low as possible. Any help is appreciated.

canhamd commented 8 years ago

This may be a rc5/mangle issue, the following issue link helped solve my problem.

#10618

mii9000 commented 8 years ago

@canhamd Thanks. But I am not on RC5 rather on Beta 8 and cannot update unfortunately.

about-code commented 8 years ago

I've also been on Beta 8 in the past and observed the same issue. Its an Angular issue not a SystemJS Bug. They had similar issues like 10618 also in their beta - most probably because of using Function.name somewhere in their code. UglifyJS tells people to be careful with mangling because statements like if (myFunc.name === "foo") obviously assumes myFunc could be 'foo' but after minification there won't be oo anymore. You've found the right options to use with UglifyJS. Try also using keep_fnames=true.

mii9000 commented 8 years ago

Not SystemJS problem