gulpfile.babel.js
function zip() {
  var dist = 'dist';
  var ext = '.html';

  function getHtmlFiles(dir) {
    return fs.readdirSync(dir)
      .filter(function(file) {
        var fileExt = path.join(dir, file);
        var isHtml = path.extname(fileExt) == ext;
        return fs.statSync(fileExt).isFile() && isHtml;
      });
  }

  var htmlFiles = getHtmlFiles(dist);

  var moveTasks = htmlFiles.map(function(file){
    var sourcePath = path.join(dist, file);
    var fileName = path.basename(sourcePath, ext);

    var moveHTML = gulp.src(sourcePath)
      .pipe($.rename(function (path) {
        path.dirname = fileName;
        return path;
      }));

    var moveImages = gulp.src(sourcePath)
      .pipe($.htmlSrc({ selector: 'img'}))
      .pipe($.rename(function (path) {
        path.dirname = fileName + path.dirname.replace('dist', '');
        return path;
      }));

    return merge(moveHTML, moveImages)
      .pipe($.zip(fileName+ '.zip'))
      .pipe(gulp.dest('dist'));
  });

  return merge(moveTasks);
}
function zip() {
  var dist = 'dist';
  var ext = '.html';

  function getHtmlFiles(dir) {
    return fs.readdirSync(dir)
      .filter(function(file) {
        var fileExt = path.join(dir, file);
        var isHtml = path.extname(fileExt) == ext;
        return fs.statSync(fileExt).isFile() && isHtml;
      });
  }

  var htmlFiles = getHtmlFiles(dist);

  var moveTasks = htmlFiles.map(function(file){
    var sourcePath = path.join(dist, file);
    var fileName = path.basename(sourcePath, ext);

    var moveHTML = gulp.src(sourcePath)
      .pipe($.rename(function (path) {
        path.dirname = fileName;
        return path;
      }));

    var moveImages = gulp.src(sourcePath)
      .pipe($.htmlSrc({ selector: 'img'}))
      .pipe($.rename(function (path) {
        path.dirname = fileName + path.dirname.replace('dist', '');
        return path;
      }));

    return merge(moveHTML, moveImages)
      .pipe($.zip(fileName+ '.zip'))
      .pipe(gulp.dest('dist'));
  });

  return merge(moveTasks);
}
function zip ( ) { var dist = 'dist' ; var ext = '.html' ; function getHtmlFiles ( dir ) { return fs . readdirSync ( dir ) . filter ( function ( file ) { var fileExt = path . join ( dir , file ) ; var isHtml = path . extname ( fileExt ) == ext ; return fs . statSync ( fileExt ) . isFile ( ) && isHtml ; } ) ; } var htmlFiles = getHtmlFiles ( dist ) ; var moveTasks = htmlFiles . map ( function ( file ) { var sourcePath = path . join ( dist , file ) ; var fileName = path . basename ( sourcePath , ext ) ; var moveHTML = gulp . src ( sourcePath ) . pipe ( $ . rename ( function ( path ) { path . dirname = fileName ; return path ; } ) ) ; var moveImages = gulp . src ( sourcePath ) . pipe ( $ . htmlSrc ( { selector : 'img' } ) ) . pipe ( $ . rename ( function ( path ) { path . dirname = fileName + path . dirname . replace ( 'dist' , '' ) ; return path ; } ) ) ; return merge ( moveHTML , moveImages ) . pipe ( $ . zip ( fileName + '.zip' ) ) . pipe ( gulp . dest ( 'dist' ) ) ; } ) ; return merge ( moveTasks ) ; }
Copy and compress into Zip
Copy and compress into Zip