Angular 2 rc 6
implemented in Typescript 2.0.2
I'm currently exploring Ahead-of-Time compilation as described here. It appears to be straightforward:
- Use
ngc
instead of the Typescript compiler to create.ngfactory.ts
files - Substitute
withplatformBrowserDynamic().bootstrapModule()
platformBrowser().bootstrapModuleFactory()
The challenge I'm facing is how to implement the first step within my existing setup. I rely on gulp-typescript 2.13.6
for converting TypeScript to JavaScript.
gulpfile.js
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json', {
//Utilize NPM-installed TS version instead of gulp-typescript's default
typescript: require('typescript')
});
gulp.task('build-ts', function () {
return gulp.src(appDev + '**/*.ts')
.pipe(ts(tsProject))
.pipe(gulp.dest(appProd));
});
So my query is; how can I incorporate these guidelines into my current tooling? How do I instruct gulp-typescript
to utilize the Angular Compiler? I've experimented with:
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('@angular/compiler') // or '@angular/compiler-cli'
});
This approach results in errors without triggering ngc
. I also attempted:
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('./node_modules/.bin/ngc')
});
While this does execute ngc
, it promptly produces an error message:
SyntaxError: Unexpected string at ngc:2: basedir=$(dirname "$(echo "$0" | sed -e 's,\,/,g')")
I suspect that the issue arises from not passing a source directory to ngc
(the correct command being ngc -p path/to/project
)
In essence, is there a means to use gulp-typescript
for streamlining the build process? (generating .ngfactory.ts
files and then compiling everything to JavaScript)