There is a template html file, and when you change a project, you need to record the time of updating the site. Gulp is following the changes.
The template file itself can also be corrected in the future and I would like to have a place in it [[Substitute time here]] and that bulp when changing a project took a file and insert a date and time into this place and produce a ready html file based on the template.
How to do this?

  • In the simplest case, use search / replace, for example gulp-replace . Or use any template engine / preprocessor, for example gulp-preprocess . - Vladimir Gamalyan

1 answer 1

As already recommended in the comments (the simplest and most effective solution), use gulp-replace :

We put:

npm install --save-dev gulp-replace 

We use:

 var gulp = require('gulp'); var replace = require('gulp-replace'); gulp.task('build', function() { var time = new Date().toTimeString(); gulp.src('src/index.html') .pipe(replace('[[Сюда подставить время]]', time)) .pipe(gulp.dest('build')); }); gulp.watch('src/**/*.*', ['build']); gulp.task('default', ['build']);