如何使用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

查看:288
本文介绍了如何使用child-process.spawn从Gulp运行NG BUILD或禁用child-process.exec中的所有输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有类似的问题,例如从一个大任务里面

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

我通过这种方式管理了Gulp来构建Angular,以免溢出输出缓冲区

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);
  });
});

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

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']);
});

我收到以下错误

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项目的可靠方法吗?

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

推荐答案

刚刚找到了答案

最后,使其与该软件包一起使用 https://github.com/IndigoUnited/node-交叉生成

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.

这篇关于如何使用child-process.spawn从Gulp运行NG BUILD或禁用child-process.exec中的所有输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆