在Gulp dest中复制目录结构 [英] Replicating directory structure in Gulp dest

查看:92
本文介绍了在Gulp dest中复制目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Gulp在几个不同的地点优化图像。这是目录结构:

I'm trying to optimize images in a couple of different locations using Gulp. This is the directory structure:

|-- app
   |-- _images
       -- image1.jpg
       -- image2.jpg
   |-- _templates
      |-- _pages
         |--_services
            |--_images
               -- image1.jpg
               -- image2.jpg

这是代码

gulp.task('images:tmp', function() {
return gulp.src(['app/templates/pages/**/*.{png,jpg,gif,svg}', 'app/images/**/*.{png,jpg,gif,svg}'], {base: 'app/'})
// Caching images that ran through imagemin
.pipe(cache(imagemin({
  interlaced: true,
})))
.pipe(gulp.dest('.tmp'))
});

我遇到的问题是应用程序的模板和页面目录被复制到.tmp的根目录以及services目录:

The problem I'm having is that the app's "templates" and "pages" directories are copied into the root of ".tmp," along with the "services" directory:

|-- .tmp
   |-- _images
       -- image1.jpg
       -- image2.jpg
   |-- _templates
      |-- _pages
         |--_services
            |--_images
               -- image1.jpg
               -- image2.jpg

我只想在根目录下的services目录中,像这样:

I only want the "services" directory in the root, like so:

|-- .tmp
   |-- _images
       -- image1.jpg
       -- image2.jpg
   |-- _services
       |--_images
          -- image1.jpg
          -- image2.jpg

如何编写复制上述目录结构的任务?感谢您的帮助!

How do I write the task to replicate the directory structure above? Thanks in advance for your help!

推荐答案

谢谢,maoizm。编辑第二个var stream1以读取var stream2并删除显然多余的内容后,这对我有用。来自溪流。

Thanks, maoizm. This worked for me after editing the second "var stream1" to read "var stream2" and removing the apparently superfluous ); from the streams.

gulp.task('images:tmp', function() {
  var stream1 = gulp.src('app/templates/pages/**/*.{png,jpg,gif,svg}')
              .pipe(cache(imagemin({interlaced: true})))
              .pipe(gulp.dest('.tmp'));            
  var stream2 = gulp.src('app/images/**/*.{png,jpg,gif,svg}',{base: 'app/'})
              .pipe(cache(imagemin({interlaced: true})))
              .pipe(gulp.dest('.tmp'));            
  return merge(stream1,stream2);
});

这篇关于在Gulp dest中复制目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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