如何使用 gulp 递归地复制目录? [英] How do I copy directories recursively with gulp?

查看:26
本文介绍了如何使用 gulp 递归地复制目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将项目从工作目录暂存到服务器(同一台机器).使用以下代码:

I am trying to stage a project from a working directory to a server (same machine). Using the following code:

gulp.src([
    'index.php',
    'css/**',
    'js/**',
    'src/**',
])
.pipe(gulp.dest('/var/www/'));

我希望看到所有文件都被复制.然而,它使 dir 结构变平 - 所有目录都被复制,但每个文件都放在根 /var/www

I would expect to see all the files copied. However it flattens the dir structure - all directories are copied but every file is placed in the root /var/www

Gulp 似乎是一个很棒的构建工具,但复制项目确实应该是一个简单的过程吗?

Gulp seems like a great build tool but copying items should be a simple process surely?

推荐答案

原来复制一个完整的目录结构gulp需要为你的gulp.src() 方法.

Turns out that to copy a complete directory structure gulp needs to be provided with a base for your gulp.src() method.

所以 gulp.src( [ files ], { "base" : "." }) 可以在上面的结构中使用递归复制所有目录.

So gulp.src( [ files ], { "base" : "." }) can be used in the structure above to copy all the directories recursively.

如果你像我一样忘记了这一点,那么试试吧:

If, like me, you may forget this then try:

gulp.copy=function(src,dest){
    return gulp.src(src, {base:"."})
        .pipe(gulp.dest(dest));
};

这篇关于如何使用 gulp 递归地复制目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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