Angular 2 rc 6
coded in typescript
I've been using SystemJS-builder
to bundle my scripts into one bundle.js
, thus reducing my http requests tremendously. I use the buildStatic()
method.
I've just noticed that when I use lazy-loaded routes, trying to navigate to such a route throws this error:
EXCEPTION: Uncaught (in promise): TypeError: this._system(...).import is not a function
Can SystemJS-builder be used to bundle an Angular 2 project that uses lazy loaded routes?
gulpfile.js
var typescript = require('gulp-typescript');
var tsProject = typescript.createProject('tsconfig.json');
var Builder = require('systemjs-builder');
//typescript compilation
gulp.task('build-ts', function () {
return gulp.src(appDev + '**/*.ts')
.pipe(typescript(tsProject))
.pipe(gulp.dest(appProd));
});
//transpile typescript into JS first ('build-ts'), then bundle JS files
gulp.task('bundle',['build-ts'], function() {
var builder = new Builder('', './systemjs.config.js');
return builder
.buildStatic(appProd + '/main.js', appProd + '/bundle.js', {encodeNames:false})
.then(function() { console.log('Build complete'); })
.catch(function(err) { console.log(err); });
});
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./dist"
},
"filesGlob": [
"./dev/**/*.ts",
"!./node_modules/**/*.ts"
],
"exclude": [
"node_modules",
"typings"
]
}
Let me know what more info you need. I wasn't sure what else would be relevant.