2016-07-15 60 views
1

我想捆綁我的應用程序與systemjs生成器。它是一個「核心」應用程序,其中有angular2。然後其他組件被懶惰地加載到核心中。目前Iam捆綁了我的核心,這是可行的,但其他組件因此會獲得404,因爲它們正在搜索angular2的舊路徑。SystemJS生成器,捆綁沒有Angular2懶惰加載

我想要捆綁的組件,但沒有angular2,組件然後使用我的核心。我想我爲此使用buildStatic?我只編譯ts文件到js。

有些片斷是我的嘗試:

建築,工程的核心是:

gulp.task('bundle:js', function() { 
    var builder = new SystemBuilder('dist', './src/systemjs.config.js'); 
    return builder.buildStatic('app', 'dist/app.js'); 
}); 

在我的index.html我加載然後app.js文件。現在是2MB左右。

然後延遲加載組件搜索: https://IP/@angular/router-deprecated導致404

我們的「硬」的部分:

gulp.task('build:static', function() { 
    var builder = new SystemBuilder('', './dist/systemjs.config.js'); 
    builder.buildStatic('dist/start.component.js', 'dist/start.component.static.js', { 
    defaultExtension: 'js', 
    globalName: 'test', 
    globalDeps: { 
    '@angular': '@angular' 
    } 
}); 
}); 

這我得到一個JS文件後這大約是1 ,1MB。所以我認爲其中沒有angular2?

如果我現在嘗試啓動我的應用程序,它告訴我:

EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on StartComponent 

我在StartComponent的指令。我的錯是什麼?這是甚至可能我是如何做到這一點?

謝謝!

+0

使用builder.bundle()然後它工作。 –

回答

0

我需要使用「system.bundle()」才能正常工作。

+1

嗨,@Mamas,你願意多解釋一下嗎?我面臨類似的問題,我不知道如何解決它。爲什麼build.bundle()修復你的問題?我也有一個問題在stackoverflow http://stackoverflow.com/questions/38944257/create-multiple-bundles-with-systemjs-builder-for-an-angular2-application – David