有一个类似的问题,例如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);
});
});
不幸的是,这只能作为临时解决方案使用,因为只要Angular项目中的文件数量持续增长,child-process.exec的输出缓冲区很快就会溢出,所以我想要使用child-process.spawn从Gulp构建Angular,但每次执行此
// This is how I want to make it to work
gulp.task('build', ['compile'], () => {
child.spawn('ng', ['build']);
});
我收到以下错误
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
有人知道从Gulp构建Angular 2项目的任何可靠方法吗?
答案 0 :(得分:4)
刚刚找到答案How do I debug "Error: spawn ENOENT" on node.js?
最后,让它使用此包https://github.com/IndigoUnited/node-cross-spawn
const spawn = require('cross-spawn');
gulp.task('build', ['compile'], () => {
spawn('ng', ['build'], { stdio: 'inherit' });
});
它就像一个魅力,但如果有人知道潜在的问题或缺点,请不要犹豫发表新的答案或评论。