gulp-less icon indicating copy to clipboard operation
gulp-less copied to clipboard

Gulp 4 and mtime on output css file

Open WraithKenny opened this issue 6 years ago • 3 comments

Gulp 4 intentionally avoids updating the mtime of output files, as a "new feature."

As per https://github.com/gulpjs/gulp/issues/2193#issuecomment-399168738 gulp-less should deliberately update the mtime of the output css file itself, else the file will always retain it's old mtime (for example, my compiled css file, which I've changed today, still says last updated aug 24th).

WraithKenny avatar Sep 12 '18 18:09 WraithKenny

A workaround in the meantime is

.pipe( through2.obj( function( file, enc, cb ) {
	var date = new Date();
	file.stat.atime = date;
	file.stat.mtime = date;
	cb( null, file );
}) )
.pipe( gulp.dest( './' ) )

(This is what I used to test... I didn't actually compile gulp-less and really test.)

WraithKenny avatar Sep 12 '18 20:09 WraithKenny

👍 This change in gulp 4 breaks plugins such as gulp-less-changed, gulp-newer, et al. that rely on the output file times for incremental build optimisation.

bingnz avatar Sep 15 '18 14:09 bingnz

I am attempting to utilize the work around solution because it is hosing up my ability to add versioning to css files. I understand that this has nothing to do with LESS but any help would be appreciated. I would like to add the pipe that WraithKenny started above:

.pipe( through2.obj( function( file, enc, cb ) { var date = new Date(); file.stat.atime = date; file.stat.mtime = date; cb( null, file ); }) )

How can I add that pipe to work with the following function

function cssversion () { return gulp.src("_cms/templates/layouts/headBotto*.php") .pipe(versionNumber({ append: { 'to': [ {'type': 'css', attr : ['href'], key : '_v', value: '%DT%', 'cover' : 1 } ] }
})) .pipe(through2.obj( function( file, enc, cb ) { let date = new Date(); file.stat.atime = date; file.stat.mtime = date; cb( null, file ); }) ) .pipe(gulp.dest("_cms/templates/layouts/")); }

FYI, this new "feature" is really annoying

seoMattH avatar Feb 23 '19 20:02 seoMattH