SkeLLLa/gulp-version-append

version append in gulp watch task

mrcarl79 opened this issue · 3 comments

If I put this in a gulp watch task, watching package.json the version number does not update?

This is the shortened gulp file I'm using, should what I'm trying to do work?

The html task does run, but it just never changes the version number. If I stop the gulp task and restart it then updates the version, it's like it uses a cached version of the package.json which only updates if you restart the gulp task.

/// <binding Clean='clean' />
"use strict";

var gulp = require('gulp'),
  versionAppend = require('gulp-version-append');

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

gulp.task('html', function() {
  return gulp
    .src(['app/**/*.html'])
    .pipe(versionAppend(['html', 'js', 'css']))
    .pipe(gulp.dest('dist'));
});

gulp.task('watch', function() {
  gulp.watch(['app/**/*.html', 'package.json'], ['html']);
});

@mrcarl79, yes. It uses require under the hood, so it loads package.json only once and uses cached version. I've done it in such way because I used it only for "release" builds that usually doesn't contain watch tasks.

As an alternative for watch tasks you can use timestamp or guid:

.pipe(versionAppend(['html', 'js', 'css'], {appendType: 'timestamp'}))
or 
.pipe(versionAppend(['html', 'js', 'css'], {appendType: 'guid'}))

For more examples see examples folder.

But usally for watch tasks I just don't use this plugin, because when I develop something I can drop cache by myself right in browser :), and this plugin is mostly should be used within production builds, to drop cache, for example, on cdn-s.

That makes sense thinking about it more :) Thanks for the help and the useful plugin!

No problem :). Closing issue for not. If you have more questions feel free to reopen.