gulp-rev: Merge is broken on 3.0.0

I just updated the appendExisting (https://github.com/sindresorhus/gulp-rev/issues/65#issuecomment-68610591) option to merge (https://github.com/sindresorhus/gulp-rev/releases/tag/v3.0.0) and now the manifest file is not being updated 😦

My gulpfile.js


var publicPath = 'public/'
gulp.task('js', function() {
  return gulp.src(scriptsPath + 'main.js', { base: path.join(process.cwd(), 'public/app') } )
    .pipe(browserify({
      insertGlobals: true,
      debug: true
    }))
    // Bundle to a single file
    .pipe(concat('scripts/app.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(publicPath))
    .pipe(rev.manifest({
      base: publicPath,
      merge: true
    }))
    .pipe(gulp.dest(publicPath))
});

The existing rev-manifest.json file is

{
  "styles/main.css": "styles/main-23ea264f.min.css"
}

The app.js is correctly minified and rev’d but the manifest file is not updated.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

I’ve been playing with this for a while, and it looks like ā€œthe right oneā€ (last example from #77) isn’t right. When you don’t set path to your manifest file, it uses default which is: ā€˜rev-manifest.json’. But what that means is:

process.cwd() + '/rev-manifest.json';

What get’s passed to vinyl is:

{
    path: 'rev-manifest.json',
    merge: true,
    base: process.cwd() + '/dist'
}

And when that ends up in:

path.relative(this.base, this.path); // returns  ../rev-manifest.json

…it returns ā€˜ā€¦/rev-manifest.json’. So gulp.dest goes one directory back from ā€˜dist’ and writes ā€˜rev-manifest.json’ in cwd. So, if we want ā€˜rev-manifest.json’ inside ā€˜dist’, ā€œthe right oneā€ should look like this:

//...
.pipe(rev())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest('dist/rev-manifest.json', {base: process.cwd()+'/dist', merge: true})
.pipe(gulp.dest('dist'));

As an example, I made a setup like this:

  • cwd: /home/username/Code/playground
  • base: process.cwd() + ā€˜/public/assets/js’
  • gulp.dest(ā€˜ā€™);

So it resolved to: ā€˜ā€¦/…/…/rev-manifest.json’, which is: ā€˜/home/rev-manifest.json’, which is error (access permissions).

If this is expected behavior, maybe the docs should emphasize this, something like gulp-util does with their ā€˜new File(obj)’. I think that people expect to see their ā€˜rev-manifest.json’ in their gulp.dest location if they don’t mess with the options.

I have also been struggling with this.

So, if we want ā€˜rev-manifest.json’ inside ā€˜dist’, ā€œthe right oneā€ should look like this:

//...
.pipe(rev())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest('dist/rev-manifest.json', {base: process.cwd()+'/dist', merge: true})
.pipe(gulp.dest('dist'));

This is rather mind boggling and totally not intuitive. But it does work.

It works doing this trick

.pipe(rev.manifest('public/rev-manifest.json', {merge: true}))
.pipe(gulp.dest(''));

Has @bobthecow said here https://github.com/sindresorhus/gulp-rev/pull/77#issuecomment-68076646

@nfantone thanks I just managed to get it work following your hack… pheeeew šŸ˜„