简体   繁体   English

Gulp不会按预期复制所有文件

[英]Gulp doesn't copy all files as expected

I tried to create a gulpfile.js for my personal website project. 我试图为我的个人网站项目创建一个gulpfile.js。 I've never done this before but with a little 'trial and error' it now works in an acceptable way. 我之前从未这样做过,但有一点'试错'现在它以可接受的方式运作。

The only thing that doesn't work even after 1000 modifications is simple copying files and folders. 即使经过1000次修改,唯一不起作用的是简单复制文件和文件夹。

var files = {
  data_src : [
    './files.json',
    'data/**/*.*'
  ],
  distribution_dest : '_distribution'
};

gulp.task('copy-data', function() {
  gulp.src(files.data_src, { base: './' })
    .pipe(gulp.dest(files.distribution_dest))
    .pipe(notify({message: 'Data copied for distribution!'}));
});

This should copy all sub-folders and files to the gulp.dest . 这应该将所有子文件夹和文件复制到gulp.dest But it copies only half of them, some folders will be ignored even if I change their names etc. (no special characters, same subfolder structure as the once that got copied correctly ...) - nothing worked. 但它只复制了其中的一半,即使我更改了名称等,也会忽略一些文件夹。(没有特殊字符,与正确复制的一次相同的子文件夹结构......) - 没有任何效果。 I just can't see any pattern in this. 我只是看不到任何模式。

There is no error message while running gulp. 运行gulp时没有错误消息。 Nothing that would help me find the error. 没有什么可以帮助我找到错误。

Why are some folders or files excluded from copying? 为什么某些文件夹或文件被排除在复制之外?


I use base to keep the folder / sub-folder structure; 我用base来保存文件夹/子文件夹结构; tried with and without 'base' -> no effects on the copying process. 尝试使用和不使用“base” - >对复制过程没有影响。

I also changed the position of the 'copy-data' task in the run-list. 我还改变了运行列表中“复制数据”任务的位置。 Actually it's the first task to run. 实际上这是第一个运行的任务。 There seems to be no change in behavior no matter if it's the first or the last one. 无论是第一个还是最后一个,行为似乎都没有变化。

gulp.task('default', function() {
  gulp.run('copy-data', 'custom-sass', 'framework-sass', 'custom-js', 'framework-js', 'replace-tags', 'browser-sync');
    ... some watches ...
});

The structure of the data folder looks like these: 数据文件夹的结构如下所示:

./data
   |-doc
   |---content
   |---template
   |-img
   |---chart
   |---icon
   |---logo
   |---pattern
   |---people
   |---photo
   |---symbol
   |-----brandklassen
   |-----brandschutzzeichen
   |-----gebotszeichen
   |-----gefahrensymbole
   |-----rettungszeichen
   |-----verbotszeichen
   |-----verkehrsrechtzeichen
   |-----warnzeichen
   |---wallpaper

/data/doc and all subfolders are ok. /data/doc和所有子文件夹都可以。
/data/img/chart to /data/img/people are also ok. /data/img/chart/data/img/people也行。

Within /data/img/photo only 14 out of 21 images are copied. /data/img/photo只复制了21张图片中的14张。
/data/img/symbol with sub-folders and /data/img/wallpaper were ignored completely. 带有子文件夹和/data/img/wallpaper /data/img/symbol被完全忽略。

SOLVED IT MYSELF! 解决了我自己! The problem was caused by async operating tasks. 该问题是由异步操作任务引起的。 Adding a return forced gulp to complete the copying process before continuing! 在继续之前添加return强制gulp以完成复制过程!

gulp.task('copy-data', function() {
    return gulp.src(files.data_src, { base: './' })
    .pipe(gulp.dest(files.distribution_dest))
    .pipe(notify({message: 'Data copied for distribution!'}))
});

Now all images will be copied! 现在所有图像都将被复制!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM