gulp添加时间戳

Mondo
  • 945

想给项目添加版本,用gulp-rev生成替换的json是总是只有生成两个对应的css

/ 生成输出路径
function getDistFolder(distPath) {
  return `${distFolder}/${distPath}`;
}

// -----------
// LESS 处理
// -----------

// LESS 编译
function compileLess(input, base, output, watch, min, sourcemaps) {
  return gulp.src(input, {base: base})
    .pipe($.plumber())
    .pipe(watch ? $.watch(input, {base: base}) : noop())
    .pipe(watch || !!argv.using ? $.using({prefix: 'Using less'}) : noop())
    .pipe(sourcemaps ? $.sourcemaps.init() : noop())
    .pipe($.less())
    .pipe(min ? $.cleanCss() : noop())
    .pipe(sourcemaps ? $.sourcemaps.write() : noop())
    .pipe($.rev())
    .pipe(gulp.dest(output)) 
    .pipe($.rev.manifest())
    .pipe(gulp.dest(output)) 
}

function compRev(output, distPath) {  
  return gulp.src([output + '/*.json', distPath + '/**/**/*.html'])
  .pipe(revCollector({
      replaceReved: true
  }))
  .pipe(gulp.dest(distPath));
}

gulp.task('admin:rev', function () {
  log('替换开始');
  return compRev(getDistFolder('admin/css'), getDistFolder('admin'));
});
gulp.task('school:rev', function () {
  return compRev(getDistFolder('school/css'), getDistFolder('school'));
});
gulp.task('oss:rev', function () {
  return compRev(getDistFolder('oss/css'), getDistFolder('oss'));
});

// 定制 bootstrap
gulp.task('less:bootstrap:admin', () => {
  return compileLess(resetPath(src.less.bootstrap, 'admin'), '', getDistFolder('admin/css'), false, !!argv.min, !!argv.sourcemaps);
});
gulp.task('less:bootstrap:school', () => {
  return compileLess(resetPath(src.less.bootstrap, 'school'), '', getDistFolder('school/css'), false, !!argv.min, !!argv.sourcemaps);
});
gulp.task('less:bootstrap:oss', () => {
  return compileLess(resetPath(src.less.bootstrap, 'oss'), '', getDistFolder('oss/css'), false, !!argv.min, !!argv.sourcemaps);
});

// 监视 bootstrap
gulp.task('watch:bootstrap:admin', () => {
  gulp.watch(resetPath(src.less.bootstrapWatch, 'admin'), ['less:bootstrap:admin']);
});
gulp.task('watch:bootstrap:school', () => {
  gulp.watch(resetPath(src.less.bootstrapWatch, 'school'), ['less:bootstrap:school']);
});
gulp.task('watch:bootstrap:oss', () => {
  gulp.watch(resetPath(src.less.bootstrapWatch, 'oss'), ['less:bootstrap:oss']);
});

// 通用 app.css
gulp.task('less:common:admin', () => {
  return compileLess(resetPath(src.less.common, 'admin'), '', getDistFolder('admin/css'), false, !!argv.min, !!argv.sourcemaps);
});
gulp.task('less:common:school', () => {
  return compileLess(resetPath(src.less.common, 'school'), '', getDistFolder('school/css'), false, !!argv.min, !!argv.sourcemaps);
});
gulp.task('less:common:oss', () => {
  return compileLess(resetPath(src.less.common, 'oss'), '', getDistFolder('oss/css'), false, !!argv.min, !!argv.sourcemaps);
});

项目路径

图片描述

图片描述

回复
阅读 1.8k
1 个回答
✓ 已被采纳

问题解决了,自己写法有问题。
并没有等所有文件生成后才来对静态文件进行时间戳添加,具体可参考

你知道吗?

宣传栏