如何通过 Gulp 将 HTML 减少到没有空格的单行

How to reduce HTML to a single line with no whitespace via Gulp

我正在尝试使用 Gulp 缩小 HTML 以删除所有换行符和白色 space 因此整个代码内容仅位于一行并且没有多余的白色space 喜欢制表符和 spaces,包括嵌入式 JavaScript 和 CSS.

我已经尝试 gulp-minify, but I do not see the output or compression options for that, which leaves me cross-eyed. I thought that was one of the common functions of minification. This beautifier/minifier 通过它的缩小按钮来精确地完成我需要的功能,但我需要通过 Gulp 来实现该功能。

好吧,我要疯了。提前致谢。

const gulp = require("gulp");
const minHTML = require('gulp-htmlmin');

gulp.task("htmlMin", function () {
  return (
    gulp
      .src("./*.html")
      .pipe(minHTML({ collapseWhitespace: true }))
      .pipe(gulp.dest("dist"))
  );
});

exports.default = gulp.series("htmlMin");

并且 运行 它只需要 gulp 在命令行中。

按照@Cully 在评论中的建议使用 gulp-htmlmin,我已经这样做了。

  ~/replace ==>  gulp
[01:23:36] Using gulpfile ~\OneDrive\Test Bed\replace\gulpfile.js
[01:23:36] Starting 'default'...
[01:23:36] Starting 'htmlMin'...
[01:23:36] Finished 'htmlMin' after 127 ms
[01:23:36] Finished 'default' after 132 ms