如何复制多个文件并使用Gulp保持文件夹结构? [英] How to copy multiple files and keep the folder structure with Gulp?

查看:90
本文介绍了如何复制多个文件并使用Gulp保持文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gulp将文件从一个文件夹复制到另一个文件夹

I am trying to copy files from one folder to another folder using gulp

gulp.task('move-css',function(){
  return gulp.src([
    './source/css/one.css',
    './source/other/css/two.css'

    ]).pipe(gulp.dest('./public/assets/css/'));
});

以上代码复制 one.css & ; two.css public / assets / css 文件夹

Above code is copying one.css & two.css to public/assets/css folder

如果我使用 gulp.src('。/ source / css / *。css'),它会将所有CSS文件复制到 public / assets / css 这不是我想要的文件夹

And if I use gulp.src('./source/css/*.css') it will copy all CSS files to public/assets/css folder which is not what I want

我的问题是如何选择多个文件并保留文件夹结构?

My question is how to select multiple files and keep the folder structure?

推荐答案

要实现此目的,请指定 base

To achieve this please specify base.


¶基础 - 指定相对于cwd的文件夹。默认是glob开始的地方。保存在 .dest()

¶ base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in .dest()





在您的情况下,它将是:


In your case it would be:

gulp.task('move-css',function(){
  return gulp.src([
      './source/css/one.css',
      './source/other/css/two.css'
  ],  {base: './source/'}) 
  .pipe(gulp.dest('./public/assets/'));
});

文件夹结构:

|-gulpfile.js
|-source
|   |-css
|   |-other
|      |-css
|-public
|   |-assets

这篇关于如何复制多个文件并使用Gulp保持文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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