0

Since yesterday something strange has started happening with my gulp-watch task. Afaik, all I did was change the destination but I can reproduce with the simple gulpfile posted below:

I have a file structure like this:

src/html/stuff/file.html
src/js/something/file.js

Whenever there is a change I want it relflected in the build folder but when I run the gulp watch:stuff below I get the following output:

build/html/stuff/file.html
build/stuff/file.html
build/js/something/file.js
  • Where is that extra build/stuff/file.html file coming from?
  • What is wrong my watch function wrong?

gulpfile

var gulp = require('gulp');
var watch = require('gulp-watch');

gulp.task('watch:stuff', function () {
    var pattern = ['src/html/**/*.html', 'src/js/**/*.js'];

    gulp.src(pattern, { base : './src/' })
    .pipe(watch({glob: pattern, emit : 'all', verbose: true},
                function(files) {
                    files.pipe(gulp.dest('./build'));
                }
               )
         );
});

Using gulp(3.8.8), gulp-watch(0.7.0)

chriskelly
  • 7,526
  • 3
  • 32
  • 50
  • do you want files to be flattened in `build` folder, like `build/file.html`, and `build/file.js`, then you can use [gulp-flatten](https://www.npmjs.org/package/gulp-flatten). If this helps, I will post as an answer. – user3995789 Sep 24 '14 at 11:09
  • Thanks but I am most interested in keeping an exact copy. I just don't want the extra files appearing. In the example I only show one file but in reality my build folder is filling with unwanted files and folders. – chriskelly Sep 24 '14 at 11:35
  • remove the `base` option and try again. – user3995789 Sep 24 '14 at 11:42
  • user3995789: That worked perfectly! Now I just need to figure out why it worked yesterday *with* the base. Thanks so much. Post an answer and so I can accept it. – chriskelly Sep 24 '14 at 12:05

1 Answers1

2

remove the base option, probably It confuses the gulp.src somehow, I don't know.

user3995789
  • 3,452
  • 1
  • 19
  • 35