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

How to run NG BUILD from Gulp using child-process.spawn or disable all output in child-process.exec

有类似这样的问题,从gulp任务内部调用" ng build"

我以这种方式管理了Gulp以构建Angular而不溢出输出缓冲区

1
2
3
4
5
6
7
8
9
10
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);
  });
});

不幸的是,这只能用作临时解决方案,因为只要Angular项目中的文件数量持续增长,child-process.exec的输出缓冲区迟早就会溢出,因此我想使用child-process。 从Gulp生成以构建Angular,但是每次执行此操作时

1
2
3
4
5
// This is how I want to make it to work

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

我收到以下错误

1
2
3
4
5
6
7
8
9
10
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! [email protected] server-start: `gulp`
npm ERR! Exit status 1

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


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

最后,使其与该程序包一起工作https://github.com/IndigoUnited/node-cross-spawn

1
2
3
4
5
const spawn = require('cross-spawn');

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

它的作用就像一种魅力,但是,如果有人知道潜在的问题或不利之处,请毫不犹豫地发布新的答案或评论。