1

There is a similar question like this Call "ng build" from inside a gulp task

I managed my Gulp to build Angular this way to not overflow the output buffer

const child = require('child_process');

// Temporary solution, progress option makes angular more quiet, 
// but I need to shut it up completely

gulp.task('build', ['compile'], (cb) => {
  child.exec('ng build --progress false', (e, stdout, stderr) => {
    cb(e);
  });
});

Unfortunately, this can be used only as a temporary solution because as far as number of files in Angular project continues to grow, soon or later output buffer of child-process.exec will overflow, so I'd like to use child-process.spawn to build Angular from Gulp, but every time I execute this

// This is how I want to make it to work

gulp.task('build', ['compile'], () => {
  child.spawn('ng', ['build']);
});

I get the following error

Error: spawn ng build ENOENT
    at exports._errnoException (util.js:1018:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cms.angular@1.0.0 server-start: `gulp`
npm ERR! Exit status 1

Does anybody know any reliable way to build Angular 2 project from Gulp?

Anonymous
  • 1,823
  • 2
  • 35
  • 74

1 Answers1

8

Just found an answer How do I debug "Error: spawn ENOENT" on node.js?

Finally, made it working with this package https://github.com/IndigoUnited/node-cross-spawn

const spawn = require('cross-spawn');

gulp.task('build', ['compile'], () => {
  spawn('ng', ['build'], { stdio: 'inherit' });
});

It works like a charm, but if somebody knows about potential issues or downsides, don't hesitate to post a new answer or comment.

Anonymous
  • 1,823
  • 2
  • 35
  • 74