删除文件一饮而尽任务 [英] Deleting files in a gulp task

查看:207
本文介绍了删除文件一饮而尽任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想采取一些源文件,并将其复制到打造一口任务/ premium 建立/免费,然后从删除一些额外的文件
编译/免费

I have a gulp task in which I want to take some source files and copy them to build/premium and build/free and then remove some extra files from build/free.

我当时试图这样做:

gulp.task("build", ["clean"], function () {
  gulp.src(["src/*", "!src/composer.*", "LICENSE"])
    .pipe(gulp.dest("build/premium"))
    .pipe(del(["build/free/plugins/*", "!build/free/plugins/index.php"]))
    .pipe(gulp.dest("build/free"));
});

这会导致一个错误:

Which results in an error:

TypeError: dest.on is not a function
    at DestroyableTransform.Stream.pipe (stream.js:45:8)
    at Gulp.<anonymous> (/Users/gezim/projects/myproj/gulpfile.js:9:6)

我如何做到这一点的删除端口?是否有共有更好的方法来做到这一点?

How do I accomplish this the deleting port? Is there a better way altogether to do this?

推荐答案

我会使用吞掉过滤只有什么不应该从第二目的地复制到下降。

I would use gulp-filter to drop only what should not be copied from the 2nd destination.

我间preTED任务的意图在的src 想要的一切present是在 present构建/ premium 。然而,编译/免费应排除这原本是的src /插件但仍应包括的src /插件/的index.php 。

I interpreted the intent of the task as wanting everything present in src to be present in build/premium. However, build/free should exclude everything which was originally in src/plugins but should still include src/plugins/index.php.

下面是一个工作gulpfile:

Here is a working gulpfile:

var gulp = require("gulp");
var filter = require("gulp-filter");
var del = require("del");

gulp.task("clean", function () {
  return del("build");
});

gulp.task("build", ["clean"], function () {
  return gulp.src(["src/**", "!src/composer.*", "LICENSE"])
    .pipe(gulp.dest("build/premium"))
    .pipe(filter(["**", "!plugins/**", "plugins/index.php"]))
    .pipe(gulp.dest("build/free"));
});

传递给模式过滤器相对的路径。因为 gulp.src 模式有的src / ** 这意味着他们是相对于 SRC

The patterns passed to filter are relative paths. Since the gulp.src pattern has src/** it means they are relative to src.

还要注意的是删除不能传递直接到 .pipe()因为它返回一个承诺。它可以从一个任务返回,如清洁任务一样。

Note also that del cannot be passed straight to .pipe() as it returns a promise. It can be returned from a task, like the clean task does.

这篇关于删除文件一饮而尽任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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