gulp-version-num

3.0.0 • Public • Published

gulp-version-num

前端项目链接自动添加版本号_=xxxxx,配置灵活,支持为seajs引入模块添加版本号。

安装

npm install gulp-version-num --save-dev

使用

gulpfile.js:
var options = {
  //参数名称
  paramName: '_',
  //文件后缀
  suffix: ['css', 'js', 'html'],
  // 参数替换还是追加replace append
  mode: 'append',
  // version  guid timestamp
  paramType: 'timestamp',
  // 匹配模式为 xx [=|+|:] xx/xx.[suffix]
  assignSymbols: ["=",":","+"],
  // 只输出内容被修改的文件
  onlyOutChanged:config.outAllRepDisable,
  // 需要排除不添加版本号的链接(针对某些链接添加版本号参数会带来额外影响)
  excludeLinks:['bootstrap-material-design.min.css'],
  // 大文件提示 单位:kb
  largeSize:200,
  // 自动跳过大文件
  autoSkipLargeFile:false
}
gulp.task("transform", function () {
    return gulp
        .src(src)
        .pipe(gulpif(
            // 建议只对seajs.config所在配置文件使用seajsVersion
            ["**/seajsConfig.js"],
            gulpVersion.seajsVersion(options)
        ))
        .pipe(gulpVersion.gulpVersion(options))
        .pipe(gulp.dest("dist"));
})

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?_=212343434">
<script src="./example.js?_=212343434"></script>
<script src="./example1.js?_=212343434&code=utf-8"></script>

完整测试案例:https://github.com/heykb/gulp-version-test

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 3.0.0
    2
    • latest

Version History

Package Sidebar

Install

npm i gulp-version-num

Weekly Downloads

11

Version

3.0.0

License

ISC

Unpacked Size

119 kB

Total Files

6

Last publish

Collaborators

  • heykb