Question

I have a simple build step of my project where I mainly concatenate several files. The code looks like this:

var gulp = require('gulp');
var p = require('gulp-load-plugins')();

var srcDir = 'src/';
var src=[/*some files here*/];
var header='',footer='';

gulp.task('build',function(){

    gulp.src(src,{cwd:srcDir})
        .pipe(p.concat('sdk.js'))
        .pipe(p.header(header))
        .pipe(p.footer(footer))
        .pipe(p.jshint())
        .pipe(gulp.dest('dist/'));

});

gulp.task('watch',function(){

    gulp.watch('src/**/*.js',['build']);

});

gulp.task('default',['build','watch']);

The first build task works as expected, with execution time about 550ms:

[gulp] Starting 'build'...
[gulp] Finished 'build' after 541 ms

However, when I change something in the src folder, the build task takes very little time, although I don't use any caching:

[gulp] Starting 'build'...
[gulp] Finished 'build' after 2.37 ms

What's more, the task has no effect - the dist directory doesn't change. I noticed, however, that the files update when I kill gulp and run it again. I don't know whether it's something with gulp or the file system itself I don't understand.

Was it helpful?

Solution

It turns out that the problem was not associated with gulp - actually it was a problem with my IDE, WebStorm. While the IDE should normally update the files automatically using the mechanism described in this comment to another question (and it also did in my case not so long ago...). Otherwise it falls back to checking all the files at a time interval. The file was not being updated in my IDE view, but it was already changed by gulp, which worked all the time. Until I fix the issue with automatic reloading, using File | Synchronize results in the up-to-date version of the file being shown.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top