Angular 2 Ahead-of-Time Compiler with gulp-typescript

前端 未结 3 1623
清歌不尽
清歌不尽 2021-02-03 11:45

Angular 2 rc 6 written in Typescript 2.0.2

I\'m trying to learn Ahead-of-Time compilation as outlined here. It seems simple enough:

3条回答
  •  日久生厌
    2021-02-03 12:27

    I imagine the reason why the typescript: require(..) is not working is because gulp-typescript looks for something called typescript or tries to run the command tsc, and since the angular compiler command is ngc, it doesn't find it.

    For now, if your project is just as simple as compiling it, you can just run the command from gulp like so:

    var exec = require('child_process').exec;
    
    gulp.task('task', function (cb) {
      exec('ngc -p ""', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        cb(err);
      });
    });
    

    This requires that you have your tsconfig.json set up correctly, with the potential extra options that Google talk about here, under the Configuration heading.

    If you need the more complex functionality that the gulp-typescript package provides, I'm afraid you're either going to have to develop it yourself, or wait for someone else to.

提交回复
热议问题