简体   繁体   中英

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/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:

[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. I tried: *.conf * *.* . - they all enter the function correctly as the pass messages show, but no file is being copied. 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. I still don't understand this behavior. The output path 'server_etc_httpd_conf/' is explicitly given to gulp.dest.

Add the base property to gulp.src, if using relative source paths containing ..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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