简体   繁体   English

使用 gulp 进行通配未按预期工作

[英]Globbing with gulp not working as expected

This gulp.watch copies the file ../server confs/oc.fr/http.conf to the directory server_etc_httpd_conf/ when changed/saved:此 gulp.watch 在更改/保存时将文件../server confs/oc.fr/http.conf到目录server_etc_httpd_conf/中:

 gulp
  .watch(['../server confs/oc.fr/httpd.conf'])
  .on('change', function(path) {
    gulp
      .src(path)
      .on('end', function(){ log('pass 1: '+path); })
      .pipe(gulp.dest('server_etc_httpd_conf/'))
      .on('end', function(){ log('pass 2: '+path); });
  });

Output: Output:

[09:39:05] Starting 'watch'...
[09:39:12] pass 1: ../server confs/oc.fr/httpd.conf
[09:39:12] pass 2: ../server confs/oc.fr/httpd.conf

But when I change the watch list to use a wild card: .watch(['../server confs/oc.fr/.']) the output messages are identical, but the file does not actually get copied.但是当我将监视列表更改为使用通配符时: .watch(['../server confs/oc.fr/.']) output 消息是相同的,但文件实际上并没有被复制。 I tried: *.conf * *.* .我试过: *.conf * *.* . - they all enter the function correctly as the pass messages show, but no file is being copied. - 他们都正确地输入了 function,因为通过消息显示,但没有文件被复制。 What's wrong?怎么了?

EDIT: Now I discovered, that, if using the wild card .编辑:现在我发现,如果使用通配符. , gulp.dest will create a new, relative target directory server confs/oc.fr/ and store the output file there. , gulp.dest 将创建一个新的相对目标目录server confs/oc.fr/并将 output 文件存储在那里。 I still don't understand this behavior.我仍然不明白这种行为。 The output path 'server_etc_httpd_conf/' is explicitly given to gulp.dest. output 路径 'server_etc_httpd_conf/' 明确地提供给 gulp.dest。

Add the base property to gulp.src, if using relative source paths containing ..如果使用包含..

.src(path, {"base": "../server confs/oc.fr/"})

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

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