2.2.0 • Published 7 years ago

metalsmith-html-minifier-multimatch v2.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Metalsmith HTML Minifier

npm

A Metalsmith plug-in to minify HTML files using kangax/html-minifier.

Be aware that certain optimizations are enabled by default in this plug-in, some of which may not be what you want. Please read the documentation to ensure you understand what is happening to your markup and disable options as required.

Installation

The usual:

$ npm install --save metalsmith-html-minifier

How do I use this thing?

A quick example:

var Metalsmith   = require("metalsmith");
var htmlMinifier = require("metalsmith-html-minifier");
Metalsmith(__dirname)
    .use(htmlMinifier()) // Use the default options
    .build();

The above will minify all the HTML files (files ending in .html) it processes. To provide a custom glob for files to minify:

var Metalsmith   = require("metalsmith");
var htmlMinifier = require("metalsmith-html-minifier");
Metalsmith(__dirname)
    .use(htmlMinifier("*.html"))
    .build();

To pass options to the minifier (to enable or disable optimizations):

var Metalsmith   = require("metalsmith");
var htmlMinifier = require("metalsmith-html-minifier");
Metalsmith(__dirname)
    .use(htmlMinifier("*.html", {
        removeComments: false,
        // etc.
    }))
    .build();

Options

See Options Quick Reference for a full reference. Suffice it to say that the options passed to the plug-in are merged with the defaults (see below) and passed to the minifier directly.

The following options are enabled by default. To disable any of these you will need to explicitly set them to false.

OptionDescription
collapseBooleanAttributesOmit attribute values from boolean attributes
collapseWhitespaceCollapse white space that contributes to text nodes in a document tree
removeAttributeQuotesRemove quotes around attributes when possible
removeCommentsStrip HTML comments
removeEmptyAttributesRemove all attributes with whitespace-only values
removeRedundantAttributesRemove attributes when value matches default

Tests

To run the tests:

$ npm test

License

This software is released under the MIT License. See LICENSE.md for more information.