如何使用 gulp 递归地复制目录?

编程入门 行业动态 更新时间:2024-10-28 13:27:25
本文介绍了如何使用 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 递归地复制目录?

本文发布于:2023-10-09 09:23:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   如何使用   目录   gulp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!