Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-html-minimizer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-html-minimizer

Gulp plugin to minify HTML using the HTMLMinifier minifier.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by122.22%
Maintainers
1
Weekly downloads
 
Created
Source

Build Dependencies NPM Version

gulp-html-minimizer

Gulp plugin to minify HTML using the actively maintained HTMLMinifier fork.

Install

npm i --save-dev gulp-html-minimizer

Usage

const gulp = require("gulp");
const htmlMinimizer = require("gulp-html-minimizer");

export function minifyHTML() {
  return gulp
    .src("./src/index.html")
    .pipe(
      htmlMinimizer({
        // Optional option object - See below or HTMLMinifier for options
      })
    )
    .pipe(gulp.dest("./dist/"));
}

Options Quick Reference

Most of the options are disabled by default.

OptionDescriptionDefault
skipInvalidFilesFiles with parsing errors will be skipped, rather than returning an errorundefined (could be true, false)
caseSensitiveTreat attributes in case sensitive manner (useful for custom HTML tags)false
collapseBooleanAttributesOmit attribute values from boolean attributesfalse
collapseInlineTagWhitespaceDon't leave any spaces between display:inline; elements when collapsing. Must be used in conjunction with collapseWhitespace=truefalse
collapseWhitespaceCollapse white space that contributes to text nodes in a document treefalse
conservativeCollapseAlways collapse to 1 space (never remove it entirely). Must be used in conjunction with collapseWhitespace=truefalse
continueOnParseErrorHandle parse errors instead of aborting.false
customAttrAssignArrays of regex'es that allow to support custom attribute assign expressions (e.g. '<div flex?="{{mode != cover}}"></div>')[ ]
customAttrCollapseRegex that specifies custom attribute to strip newlines from (e.g. /ng-class/)
customAttrSurroundArrays of regex'es that allow to support custom attribute surround expressions (e.g. <input {{#if value}}checked="checked"{{/if}}>)[ ]
customEventAttributesArrays of regex'es that allow to support custom event attributes for minifyJS (e.g. ng-click)[ /^on[a-z]{3,}$/ ]
decodeEntitiesUse direct Unicode characters whenever possiblefalse
html5Parse input according to HTML5 specificationstrue
ignoreCustomCommentsArray of regex'es that allow to ignore certain comments, when matched[ /^!/, /^\s*#/ ]
ignoreCustomFragmentsArray of regex'es that allow to ignore certain fragments, when matched (e.g. <?php ... ?>, {{ ... }}, etc.)[ /<%[\s\S]*?%>/, /<\?[\s\S]*?\?>/ ]
includeAutoGeneratedTagsInsert tags generated by HTML parsertrue
keepClosingSlashKeep the trailing slash on singleton elementsfalse
maxLineLengthSpecify a maximum line length. Compressed output will be split by newlines at valid HTML split-points
minifyCSSMinify CSS in style elements and style attributes (uses clean-css)false (could be true, Object, Function(text, type))
minifyJSMinify JavaScript in script elements and event attributes (uses Terser)false (could be true, Object, Function(text, inline))
minifyURLsMinify URLs in various attributes (uses relateurl)false (could be String, Object, Function(text))
preserveLineBreaksAlways collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with collapseWhitespace=truefalse
preventAttributesEscapingPrevents the escaping of the values of attributesfalse
processConditionalCommentsProcess contents of conditional comments through minifierfalse
processScriptsArray of strings corresponding to types of script elements to process through minifier (e.g. text/ng-template, text/x-handlebars-template, etc.)[ ]
quoteCharacterType of quote to use for attribute values (' or ")
removeAttributeQuotesRemove quotes around attributes when possiblefalse
removeCommentsStrip HTML commentsfalse
removeEmptyAttributesRemove all attributes with whitespace-only valuesfalse (could be true, Function(attrName, tag))
removeEmptyElementsRemove all elements with empty contentsfalse
removeOptionalTagsRemove optional tagsfalse
removeRedundantAttributesRemove attributes when value matches default.false
removeScriptTypeAttributesRemove type="text/javascript" from script tags. Other type attribute values are left intactfalse
removeStyleLinkTypeAttributesRemove type="text/css" from style and link tags. Other type attribute values are left intactfalse
removeTagWhitespaceRemove space between attributes whenever possible. Note that this will result in invalid HTML!false
sortAttributesSort attributes by frequencyfalse
sortClassNameSort style classes by frequencyfalse
trimCustomFragmentsTrim white space around ignoreCustomFragments.false
useShortDoctypeReplaces the doctype with the short (HTML5) doctypefalse

Additional info

For information regarding sorting attributes / style classes, ignoring chunks of markup, preserving SVG tags & working with invalid markup see HTMLMinifier fork

Keywords

FAQs

Package last updated on 27 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc