使用gulp-usemin为每个单个文件夹创建index.html

时间:2018-05-09 09:30:39

标签: gulp gulp-usemin

我是前端 Newbi ,这是我的第一个问题 我现在尝试使用gulp-usemin

我不知道如何为每个目录制作index.html

这是我目前的目录:

|
+- CLM
|   +- TestFoder1
|          +-css
|             +-styles.css
|          +-js
|            +-script.js
|          +-index.html
|   +- TestFoder2
|          +-css
|             +-styles.css
|          +-js
|            +-script.js
|          +-index.html
+-gulpfile.js
+-package.json

我想用这样的gulp-usemin创建dist文件夹:

|
+- dist
|   +- TestFoder1
|          +-css
|             +-styles.css
|          +-js
|          +-index.html
|   +- TestFoder2
|          +-css
|             +-styles.css
|          +-js
|          +-index.html

但我无法做到这一点。只有一个.html文件出来。我不知道该怎么做。

这是我的code

  var gulp = require('gulp'),
  imagemin = require('gulp-imagemin'),
  del = require('del'),
  usemin = require('gulp-usemin'),
  rev = require('gulp-rev'),
  cssnano = require('gulp-cssnano'),
  uglify = require('gulp-uglify'),
  browserSync = require('browser-sync').create();

var slide = ['TestFolder1', 'TestFolder2', 'TestFolder3'];
var presentationName = 'CLM';

gulp.task('deleteDistFolder', function() {
  return del('./dist');
});

gulp.task('optimizeImages', function() {
  for (let i = 0; i < slide.length; i++) {
    gulp
      .src('./' + presentationName + '/' + slide[i] + '/images/*')
      .pipe(
        imagemin({
          progressive: true,
          interlaced: true,
          multipass: true,
        })
      )
      .pipe(gulp.dest('./dist/' + slide[i] + '/images'));
  }
});

gulp.task('usemin', ['deleteDistFolder'], function() {
  for (var i = 0; i < slide.length; i++) {
    gulp
      .src('./' + presentationName + '/' + slide[i] + '/*.html')
      .pipe(usemin({
  css: [function() {return rev()}, function() {return cssnano()}],
  js: [function() {return rev()}, function() {return uglify()}]
}))
.pipe(gulp.dest("./dist"));
  }
});
gulp.task('build', ['deleteDistFolder', 'optimizeImages', 'usemin']);

0 个答案:

没有答案