gulp-rev: Merge: true not working for rev.manifest()
I use gulp-rev 4 times, once for js, css, templates and for the concatenated and minified JS. The merge option is set to true. However the manifests are not merged, but overwritten. How do I get the rev.manifest() to merge? Note - I do understand that the gulp.dest() causes the file to be overwritten. But how else do you merge?
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var rev = require('gulp-rev');
var del = require('del');
var confirm = require('gulp-confirm');
//gulp runs tasks async, but that causes issues for us.
gulp.task('clean', function () {
return del([
'dist/**/*' // clean out this directory
]);
});
// Lint Task
gulp.task('lint', ['clean'], function() {
//return gulp.src('js/**/*.js')
// .pipe(jshint())
// .pipe(jshint.reporter('default'));
});
// Compile Our Sass
gulp.task('sass', ['lint'], function() {
//return gulp.src('sass/*.scss')
// .pipe(sass())
// .pipe(gulp.dest('css'));
});
gulp.task('rev-js', ['sass'], function () {
return gulp.src(['js/**/*.js'])
//.pipe(gulp.dest('dist/js')) // copy files to dist
.pipe(rev()) // revision them
.pipe(gulp.dest('dist/js')) // copy the revision files to dist
.pipe(rev.manifest("rev-manifest.json", {
merge: true // merge with the existing manifest (if one exists)
}))
.pipe(gulp.dest('dist'))
.pipe(confirm({
// Static text.
question: 'Completed rev JS. Continue?',
input: '_key:y'
}));
});
gulp.task('rev-css', ['rev-js'], function () {
return gulp.src(['css/*.css'])
//.pipe(gulp.dest('dist/css')) // copy files to dist
.pipe(rev()) // revision them
.pipe(gulp.dest('dist/css')) // copy the revision files to dist
.pipe(rev.manifest("rev-manifest.json", {
merge: true // merge with the existing manifest (if one exists)
}))
.pipe(gulp.dest('dist'))
.pipe(confirm({
// Static text.
question: 'Completed rev CSS. Continue?',
input: '_key:y'
}));
});
gulp.task('rev-templates', ['rev-css'], function () {
return gulp.src(['templates/**/*.html'])
//.pipe(gulp.dest('dist/templates')) // copy files to dist
.pipe(rev()) // revision them
.pipe(gulp.dest('dist/templates')) // copy the revision files to dist
.pipe(rev.manifest("rev-manifest.json", {
merge: true // merge with the existing manifest (if one exists)
}))
.pipe(gulp.dest('dist'));
});
// Concatenate & Minify JS
gulp.task('scripts', ['rev-templates'], function() {
gulp.src('js/**/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'))
.pipe(rev())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest("rev-manifest.json", {
merge: true // merge with the existing manifest (if one exists)
}))
.pipe(gulp.dest('dist'));
});
// Watch Files For Changes
gulp.task('watch', ['scripts'], function() {
//gulp.watch('js/*.js', ['lint', 'scripts']);
//gulp.watch('scss/*.scss', ['sass']);
});
// Default Task
gulp.task('default', ['watch']);
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 31 (3 by maintainers)
You indeed HAVE to pass the path of the manifest as parameter before the options if you want the merge to work, here is the example corrected :
I use
@bensampaio try to change the path of the rev-manifest in this line :
.pipe(rev.manifest('rev-manifest.json', { merge: true, base: buildFolder }))
to the same as the base path :.pipe(rev.manifest(buildFolder + '/rev-manifest.json', { merge: true, base: buildFolder }))
Merging is handled right here.
Everyone with this issue: your problem is likely that gulp tasks run in parallel (and async), and later tasks are overwriting earlier ones without merging their changes together. See #115 for a couple of things to try to fix your task definitions.
I agree with @goooseman ,
it working!!
I also bumped to this problem. To solve it, first I dump each files to different manifest json file. (Ex: a.json, b.json and etc). After all tasks (which has its own manifest file) finished, I use a task to merge all that files into 1 manifest file. Here is the example code:
In my opinion, the task take some times to write file. When the task finished, the file is not completely written, yet.
Currently this method works for me. But I don’t know wether this is a good way. Any suggestions is really appreciated.
@OliverJAsh I just spent 30 mins investigating the same issue, and found the same thing. I just changed
base: 'dist'
tocwd: 'dist'
and everything started working. I’ll send a PR to change the docs.edit: I also had to provide an absolute url to the file like @goooseman suggested. i’ll add that to the docs too.
vinyl-file
doesn’t pick up thebase
option we pass into it: https://github.com/sindresorhus/vinyl-file/blob/9bdbc6d9211d7d896e2e3c88afa8beb530d873b7/index.js#L19Is that a bug in
vinyl-file
?If I pass in a
cwd
option instead ofbase
, it works:Everyone with this issue:
rev.manifest
can’t tell where your existing file is if you’re writing it to another directory viagulp.dest
. It doesn’t know the future, it doesn’t know that one line later in your code you’re going to be redirecting it to another folder. It has no idea where to look unless you tell it. So pass abase
option if you’re writing your manifest somewhere else viagulp.dest
😃@bensampaio you need to supply a base for your
rev.manifest
call:@mtpultz @LoicUV Because you’ve set the
gulp.src {base}
property, the plugin is looking for an existing manifest file insidepublic/
and notpublic/build
.You may try:
base
value on yourgulp.src
tooutputFolder
{path: 'public/build/rev-manifest.json'}
option along with yourmerge
As seen in the code, the plugin looks for a manifest solely based on
opts.path
. If one is not found, thenmerge: true
becomes irrelevant.