gulp html 路径替换,gulp-file-rev

本文介绍了如何使用gulp-file-rev插件来修订项目中的静态资源文件,并替换HTML、CSS和JS中引用的路径,以实现文件版本控制。通过设置选项如hash长度、separator和algorithm,可以自定义修订方式。该插件适用于前端项目的构建流程,确保更新后的资源能够正确引用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gulp-file-rev

gulp-file-rev.svg

badge.svg

gulp-file-rev.svg

gulp-file-rev.svg

status.svg

dev-status.svg

A gulp plugin to revise files and replace references with new paths.

Usage

First, install gulp-file-rev as a development dependency:

npm install --save-dev gulp-file-rev

Then, add it to your gulpfile.js:

var gulp = require('gulp');

var gulpIf = require('gulp-if');

var fileRev = require('gulp-file-rev');

gulp.task('default', function() {

var revision = fileRev();

return gulp

.src('**/*')

// revise files

.pipe(gulpIf('**/*.{jpg,png,gif}', revision))

// replace references

.pipe(gulpIf('**/*.{html,css,js}', revision.replace))

.pipe(gulp.dest('dist'));

});

API

fileRev(options)

options

Type: Object

options.hashLength

The length of the hash.

Type: Number

Default: 8

options.separator

The separator between the filename and hash.

Type: String

Default: .

options.algorithm

The algorithm function to calculate the content hash.

Type: Function

Default: fileRev.md5

options.queryMode

If true, the plugin will put the hash to the query string instead of the filename.

Type: Boolean

Default: false

options.prefix

The prefix to prepended to the file path, which is usually used to prepend the CDN host. Please notice that you should set options.cwd properly.

Type: String

Default: ``

options.cwd

Current working directory for prefix prepending, only has an effect if options.prefix is provided.

Type: String

Default: process.cwd()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值