如何使用 child-process.spawn 从 Gulp 运行 NG BUILD 或禁用 child-process.exec 中的所有输出

Ano*_*ous 0 gulp angular

有一个类似的问题是这样的 Call "ng build" from inside a gulp task

我管理我的 Gulp 以这种方式构建 Angular 以免溢出输出缓冲区

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);
  });
});
Run Code Online (Sandbox Code Playgroud)

不幸的是,这只能用作临时解决方案,因为只要 Angular 项目中的文件数量继续增长,子进程.exec 的输出缓冲区迟早会溢出,所以我想使用子进程。 spawn 从 Gulp 构建 Angular,但每次我执行这个

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

gulp.task('build', ['compile'], () => {
  child.spawn('ng', ['build']);
});
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

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
Run Code Online (Sandbox Code Playgroud)

有人知道从 Gulp 构建 Angular 2 项目的任何可靠方法吗?

Ano*_*ous 6

刚刚找到答案如何在 node.js 上调试“错误:生成 ENOENT”?

最后,让它与这个包一起工作https://github.com/IndigoUnited/node-cross-spawn

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

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

它就像一种魅力,但如果有人知道潜在的问题或缺点,请不要犹豫,发布新的答案或评论。