How to do gulp-water work with gulp -rev?

The setup is just as simple:

gulp.task('rev-js',  function() {
  return gulp.src('/js/main.js, {base: '.'})
      .pipe(newer('_build'))
      .pipe(rev())
      .pipe(gulp.dest('_build'))
      .pipe(rev.manifest())
      .pipe(gulp.dest('_build/rev/js'));
});

gulp -newer obviously does not work here, since the destination file gets a different name. Any workaround to create gulp -newer (or gulp -changed) works in this case?

+4
source share
2 answers

In the gulp -newer options documentation, I read that it supports passing in a configuration object instead of a destination. In this configuration object, you can specify the mapping function from old to new files. Therefore, instead of

newer('_build')

You can write

newer({dest: '_build', map: mappingFn})

, - . index.js. , rev-manifest.json, . - script ( ):

gulp.task('rev-js',  function() {

  // get the existing manifest
  // todo: add logic to skip this if file doesn't exist
  var currentManifest = JSON.parse(fs.readFileSync('rev-manifest.json', 'utf8'));

  // mapping function for gulp-newer
  function mapToRevisions(relativeName) {
    return currentManifest[relativeName]
  }

  return gulp.src('/js/main.js, {base: '.'})
      .pipe(newer({dest: '_build', map: mapToRevisions}))
      .pipe(rev())
      .pipe(gulp.dest('_build'))
      .pipe(rev.manifest())
      .pipe(gulp.dest('_build/rev/js'));
});
+1

gulp-newy, . newy(). , .

1:1 1.

newy(function(projectDir, srcFile, absSrcFile) {
  // do whatever you want to here. 
  // construct your absolute path, change filename suffix, etc. 
  // then return /foo/bar/filename.suffix as the file to compare against
}

enter image description here

+1

Source: https://habr.com/ru/post/1599733/


All Articles