問題描述
我有一個(gè) gulp 任務(wù),我想獲取一些源文件并將它們復(fù)制到 build/premium
和 build/free
然后從構(gòu)建/免費(fèi)
.
我的嘗試是這樣做的:
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"));});
這會(huì)導(dǎo)致錯(cuò)誤:
TypeError: dest.on 不是函數(shù)在 DestroyableTransform.Stream.pipe (stream.js:45:8)在 Gulp.<匿名>(/Users/gezim/projects/myproj/gulpfile.js:9:6)
如何在刪除端口時(shí)完成此操作?有沒有更好的方法來做到這一點(diǎn)?
我會(huì)使用 gulp-filter
只刪除不應(yīng)該從第二個(gè)目的地復(fù)制的內(nèi)容.
我將任務(wù)的意圖解釋為希望 src
中存在的所有內(nèi)容都存在于 build/premium
中.但是,build/free
應(yīng)該排除最初在 src/plugins
中但仍應(yīng)包含 src/plugins/index.php
的所有內(nèi)容.p>
這是一個(gè)有效的 gulpfile:
var gulp = require("gulp");var filter = require("gulp-filter");變種德爾=要求(德爾");gulp.task("干凈", function () {返回德爾(構(gòu)建");});gulp.task("build", ["clean"], function () {返回 gulp.src(["src/**", "!src/composer.*", "LICENSE"]).pipe(gulp.dest("build/premium")).pipe(filter(["**", "!plugins/**", "plugins/index.php"])).pipe(gulp.dest("build/free"));});
傳遞給 filter
的模式是 relative 路徑.由于 gulp.src
模式具有 src/**
這意味著它們是相對(duì)于 src
的.
還要注意,del
不能直接傳遞給 .pipe()
,因?yàn)樗祷匾粋€(gè)承諾.它可以從任務(wù)中返回,就像 clean
任務(wù)一樣.
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
.
My attempt at that was doing this:
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.
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
.
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"));
});
The patterns passed to filter
are relative paths. Since the gulp.src
pattern has src/**
it means they are relative to src
.
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.
這篇關(guān)于在 gulp 任務(wù)中刪除文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!