gulp常用插件之gulp-htmlmin使用

更多gulp常用插件使用请访问:gulp常用插件汇总


gulp-htmlmin这是一款HTML文件压缩插件。

更多使用文档请点击访问gulp-htmlmin工具官网

安装

一键安装不多解释

npm install --save-dev gulp-htmlmin

使用

有关所有可用选项,请参见html-minifer文档。

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

gulp.task('minify', () => {
  return gulp.src('src/*.html')
        // options = {
    // removeComments: true,  //清除HTML注释
    // collapseWhitespace: true,  //压缩HTML
    // collapseBooleanAttributes: true,  //省略布尔属性的值 <input checked="true"/> ==> <input checked />
    // removeEmptyAttributes: true,  //删除所有空格作属性值 <input id="" /> ==> <input />
    // removeScriptTypeAttributes: true,  //删除<script>的type="text/javascript"
    // removeStyleLinkTypeAttributes: true,  //删除<style>和<link>的type="text/css"
    // minifyJS: true,  //压缩页面JS
    // minifyCSS: true  //压缩页面CSS
    // };
 
    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest('dist'));
});

猜你喜欢

转载自www.cnblogs.com/jiaoshou/p/12184994.html