【问题标题】:How to run NG BUILD from Gulp using child-process.spawn or disable all output in child-process.exec如何使用 child-process.spawn 从 Gulp 运行 NG BUILD 或禁用 child-process.exec 中的所有输出
【发布时间】:2018-02-01 04:08:28
【问题描述】:

有类似的问题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 项目的可靠方法吗?

【问题讨论】:

    标签: angular gulp


    【解决方案1】:

    刚刚找到答案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' });
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-12
      • 2016-06-24
      • 2013-07-12
      • 2017-02-21
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 2023-01-03
      相关资源
      最近更新 更多