Open larrybotha opened 8 years ago
If you are still interested, this is a workaround I use. (Quick example code below)
Usually, in source code paths are in one of these forms (with variants, of course):
<script src="path/to/file.js"></script>
const libSrc = 'path/to/file.js';
.my-selector {
background: url(path/to/image.png);
}
So, basically all paths that need to be replaced are followed by "
, '
or )
. We make sure the plugin replaces only matches that are followed by one of those characters.
gulpfile.js
const modifyOnlyThoseEndingWith = (ending) => {
return (filename) => {
// Other modifications specific to your build
filename += ending;
return filename;
};
};
gulp.task('revision-replace', () => {
// We need a stream to consume for each `gulp-rev-replace` call
const manifest1 = gulp.src('path/to/rev-manifest.json');
const manifest2 = gulp.src('path/to/rev-manifest.json');
const manifest3 = gulp.src('path/to/rev-manifest.json');
return gulp.src('build-dir/**')
.pipe($.revReplace({
manifest: manifest1,
modifyUnreved: modifyOnlyThoseEndingWith('\''),
modifyReved: modifyOnlyThoseEndingWith('\''),
}))
.pipe($.revReplace({
manifest: manifest2,
modifyUnreved: modifyOnlyThoseEndingWith('"'),
modifyReved: modifyOnlyThoseEndingWith('"'),
}))
// Used for CSS url() notation
.pipe($.revReplace({
manifest: manifest3,
modifyUnreved: modifyOnlyThoseEndingWith(')'),
modifyReved: modifyOnlyThoseEndingWith(')'),
}))
.pipe(gulp.dest('build-dir'));
});
Inspired by this comment from Issue #47.
Getting a false positive in a bundled js file for an external library that contains
style.css
is replaced with the rev'd string from the manifest, invalidating the bundle.