gulp 插件,避免版本差异缓存,自动添加 css、j
gulp-html-version
gulp 插件,避免版本差异缓存,自动添加 css、js 版本号
安装npm install gulp-html-version --save-dev
使用
gulpfile.js:
var gulp = require('gulp'); gulpHtmlVersion = require('gulp-html-version'); gulp.task('default', function() { return gulp.src('./*.html') .pipe(gulpHtmlVersion()) .pipe(gulp.dest('./build/')); });
html:
<link rel="stylesheet" href="./example.css"> <script src="./example.js"></script> <script src="./example1.js?code=utf-8"></script>
结果:
<link rel="stylesheet" href="./example.css?v=0.3.2"> <script src="./example.js?v=0.3.2"></script> <script src="./example1.js?code=utf-8&v=0.3.2"></script> 参数
.pipe(gulpHtmlVersion({ paramName: 'version', paramType: 'timestamp', suffix: ['css', 'js', 'jpg'] }))
参数列表
paramName
版本号参数名称,默认为 v
paramType
生成版本的参数类型,默认为 version
有三个选项。 version
: 在 package.json
中 version
作为版本号; guid
: 生成唯一字符串版本号 ; timestamp
: 生成时间戳版本号
suffix
需要在资源文件添加的版本号 默认为 ['css', 'js']
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。