gulp-community / gulp-cached

A simple in-memory file cache for gulp
MIT License
452 stars 23 forks source link

Not caching changed files #11

Closed furkanpoyraz closed 9 years ago

furkanpoyraz commented 9 years ago

The problem: gulp.src is excluding .html files with an underline at the beginning, therefore changes made in the underlined files are not getting cached.

My code:

var cache = require('gulp-cached');
gulp.task('html', function() {
  return gulp.src('app/templates/**/!(_)*.html')
    .pipe(cache('process-html'))
    .pipe(gulp.dest('.tmp'));
});

How can I tell gulp-cached to cache the underlined files too?

Thanks in advance.

yocontra commented 9 years ago

@furkanpoyraz Your glob looks like it is negating the _ files from ever being passed to gulp-cached.

Sidenote: You should never use .tmp folders or files in gulp. Your build pipeline must be doing something crazy - want to post it and I can give some pointers?

furkanpoyraz commented 9 years ago

I don't have a build task, yet. I thought it would be a good idea to store the processed .html files in a .tmp folder so I can test it with BrowserSync.

You have any better idea on solving this?

My full html task:

gulp.task('html', function() {
  var assets = ['app/styles/**/!(_)*.css'];
  nunjucksRender.nunjucks.configure(['app/templates'], {watch: false});

  return gulp.src('app/templates/**/!(_)*.html')
    .pipe(cache('process-html'))
    .pipe(nunjucksRender())
    .pipe(inject(gulp.src(assets, {read: false}), {ignorePath: 'app', addRootSlash: false}))
    .pipe(gulp.dest('.tmp'))
    .pipe(browserSync.stream());
});
yocontra commented 9 years ago

@furkanpoyraz That looks fine but you are ignoring _ files so they are not going to get passed down the pipeline. To solve your problem change your glob

furkanpoyraz commented 9 years ago

I'm ignoring them because I don't need them at the destination, but I still need to cache them.

A solution would be not to take the src from the return but to define it's own src to cache like cache('process-html')(gulp.src('app/templates/**/*.html'))

In practice:

gulp.task('html', function() {
  var assets = ['app/styles/**/!(_)*.css'];
  nunjucksRender.nunjucks.configure(['app/templates'], {watch: false});

  return gulp.src('app/templates/**/!(_)*.html')
    .pipe(cache('process-html')(gulp.src('app/templates/**/*.html')))
    .pipe(nunjucksRender())
    .pipe(inject(gulp.src(assets, {read: false}), {ignorePath: 'app', addRootSlash: false}))
    .pipe(gulp.dest('.tmp'))
    .pipe(browserSync.stream());
});
yocontra commented 9 years ago

Use gulp-if to negate the _ files from parts of the pipeline you don't want them in

akupiec commented 7 years ago

this is quite confusing that gulp-cashed is not taking into account ignored files. after simple change in config from

gulp.src(['src/**/*.html', '!src/ignoredTempates/**/*.html'])
  .pipe(cached('templates'))
  .pipe(gulp.dest('dest/'));

in to :

gulp.src(['src/*dir1/**/*.html', 'src/*dir2/**/*.html', ..etc]) 
  .pipe(cached('templates'))
  .pipe(gulp.dest('dest/'));

I experienced gain more then 2000% in execution speed on change in single file.

yocontra commented 7 years ago

@akupiec There is no possible way for gulp-cached to know about files that are not in the glob. If you don't tell src to fetch the files, then it never exists as far as the pipeline is concerned. Not sure why you thumbs downed my responses for no reason.

As for your speed increase - nice, but that doesn't have anything to do with gulp-cached. You optimized the glob you're giving to gulp.src so it has less of the file system to walk through and filter.