Gulp如何将输出保存到文件中

3
我正在使用 gulpgulp-shell。如何将输出保存到一个文件中(由gulp创建)?
return gulp.src('.')
    .pipe(shell([
        'composer install --prefer-source'
    ]));
4个回答

3
为了实现这一点,我使用 gulp-exec
gulp.task("git_log", [], function(){
    var options = {
        continueOnError: false, // default = false, true means don't emit error event
        pipeStdout: true, // default = false, true means stdout is written to file.contents
        customTemplatingThing: "test" // content passed to gutil.template()
    };
    var reportOptions = {
        err: false, // default = true, false means don't write err
        stderr: true, // default = true, false means don't write stderr
        stdout: false // default = true, false means don't write stdout
    };
    return gulp.src("somefile.txt")
        .pipe(exec("pwd", options))
        .pipe(exec.reporter(reportOptions))
        .pipe(gulp.dest('build/'));
});

0

Gulp Shell 传递的是文件,而不是它运行的命令的输出。

一个快速而简单的解决方案——并非基于 Windows 或 Gulp——就是将 shell 命令的输出直接传递到命令本身内的文件中:

return gulp.src('.')
  .pipe(shell([
    'composer install --prefer-source > composer-log.txt'
  ]));

这显然只适用于*nix环境,并且对于捕获多个命令的输出不具备良好的扩展性(尽管您可以将所有这些命令的输出追加到同一个文件中)。

-1

继续使用.pipe(gulp.dest('output.file'))


2
它只是创建一个名为output.file/project-directory/的空目录。 - Thomas
@Thomas gulp-shell只是简单地传递源文件,而不是运行在它们上面的命令的输出,因此你实际上是将当前目录导入到当前目录中。 - Nick Tomlin

-1
你最好使用“run”来完成这个任务。
gulp.task 'run',->
run ("echo Hello!")
.exec()
.pipe (gulp.dest "G:\\new.txt")

需要安装像gulp-run和gulp-exec这样的插件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接