gulp-community / gulp-less

A LESS plugin for Gulp
559 stars 116 forks source link

Gulp 4 and mtime on output css file #301

Open WraithKenny opened 6 years ago

WraithKenny commented 6 years ago

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 commented 6 years ago

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.)

bingnz commented 6 years ago

👍 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.

seoMattH commented 5 years ago

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