在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jamesknelson/gulp-rev-replace开源软件地址(OpenSource Url):https://github.com/jamesknelson/gulp-rev-replace开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-rev-replaceRewrite occurrences of filenames which have been renamed by gulp-rev TheDancingCode/gulp-rev-rewrite.Note: this package is no longer maintained. Development continues inInstall$ npm install --save-dev gulp-rev-replace UsagePipe through a stream which has both the files you want to be updated, as well as the files which have been renamed. For example, we can use gulp-useref to concatenate assets in an index.html, and then use gulp-rev and gulp-rev-replace to cache-bust them. var gulp = require('gulp');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var useref = require('gulp-useref');
var filter = require('gulp-filter');
var uglify = require('gulp-uglify');
var csso = require('gulp-csso');
gulp.task("index", function() {
var jsFilter = filter("**/*.js", { restore: true });
var cssFilter = filter("**/*.css", { restore: true });
var indexHtmlFilter = filter(['**/*', '!**/index.html'], { restore: true });
return gulp.src("src/index.html")
.pipe(useref()) // Concatenate with gulp-useref
.pipe(jsFilter)
.pipe(uglify()) // Minify any javascript sources
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(csso()) // Minify any CSS sources
.pipe(cssFilter.restore)
.pipe(indexHtmlFilter)
.pipe(rev()) // Rename the concatenated files (but not index.html)
.pipe(indexHtmlFilter.restore)
.pipe(revReplace()) // Substitute in new filenames
.pipe(gulp.dest('public'));
}); It is also possible to use gulp-rev-replace without gulp-useref: var rev = require("gulp-rev");
var revReplace = require("gulp-rev-replace");
gulp.task("revision", ["dist:css", "dist:js"], function(){
return gulp.src(["dist/**/*.css", "dist/**/*.js"])
.pipe(rev())
.pipe(gulp.dest(opt.distFolder))
.pipe(rev.manifest())
.pipe(gulp.dest(opt.distFolder))
})
gulp.task("revreplace", ["revision"], function(){
var manifest = gulp.src("./" + opt.distFolder + "/rev-manifest.json");
return gulp.src(opt.srcFolder + "/index.html")
.pipe(revReplace({manifest: manifest}))
.pipe(gulp.dest(opt.distFolder));
}); APIrevReplace(options)options.canonicalUrisType: Default: Use canonical Uris when replacing filePaths, i.e. when working with filepaths
with non forward slash ( options.replaceInExtensionsType: Default: Only substitute in new filenames in files of these types. options.prefixType: Default: `` Add the prefix string to each replacement. options.manifestType: Read JSON manifests written out by options.modifyUnreved, options.modifyRevedType: Modify the name of the unreved/reved files before using them. The filename is passed to the function as the first argument. For example, if in your manifest you have: {"js/app.js.map": "js/app-98adc164.js.map"} If you wanted to get rid of the function replaceJsIfMap(filename) {
if (filename.indexOf('.map') > -1) {
return filename.replace('js/', '');
}
return filename;
}
return gulp.src(opt.distFolder + '**/*.js')
.pipe(revReplace({
manifest: manifest,
modifyUnreved: replaceJsIfMap,
modifyReved: replaceJsIfMap
}))
.pipe(gulp.dest(opt.distFolder)); Contributors
License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论