用gulp复制文件 [英] copying files with gulp

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

问题描述

我有一个应用程序。我的应用程序源代码的结构如下所示:

I have an app. My app source code is structured like this:

./
  gulpfile.js
  src
    img
      bg.png
      logo.png
    data
      list.json
    favicon.ico
    web.config
    index.html
  deploy

我正尝试使用Gulp来复制两个文件:./img/bg。 png和./data/list.json。我想将这两个文件复制到部署目录的根目录。换句话说,任务的结果应该是:

I am trying to use Gulp to copy two files: ./img/bg.png and ./data/list.json. I want to copy these two files to the root of the deploy directory. In other words, the result of the task should have:

./
  deploy
    imgs
      bg.png
    data
      list.json

如何写入一个咕嘟咕嘟的任务来做这种复制?让我感到困惑的是,我希望我的任务能够复制两个独立的文件,而不是适合模式的文件。我知道如果我有一个模式,我可以这样做:

How do I write a Gulp task to do this type of copying? The thing that is confusing me is the fact that I want my task to copy two seperate files instead of files that fit a pattern. I know if I had a pattern, I could do this:

var copy = require('gulp-copy');
gulp.task('copy-resources', function() {
  return gulp.src('./src/img/*.png')
    .pipe(gulp.dest('./deploy'))
  ;
});

然而,我仍然不确定如何用两个独立的文件来做到这一点。

Yet, I'm still not sure how to do this with two seperate files.

谢谢

Thanks

推荐答案

您可以为每个目标目录创建单独的任务,他们使用一般的copy-resources任务。

You can create separate tasks for each target directory, and then combine them using a general "copy-resources" task.

gulp.task('copy-img', function() {
  return gulp.src('./src/img/*.png')
    .pipe(gulp.dest('./deploy/imgs'));
});

gulp.task('copy-data', function() {
  return gulp.src('./src/data/*.json')
    .pipe(gulp.dest('./deploy/data'));
});

gulp.task('copy-resources', ['copy-img', 'copy-data']);

这篇关于用gulp复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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