All Projects → whymarrh → metalsmith-html-minifier

whymarrh / metalsmith-html-minifier

Licence: other
A Metalsmith plug-in to minify HTML files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to metalsmith-html-minifier

permalinks
A Metalsmith plugin for permalinks.
Stars: ✭ 61 (+165.22%)
Mutual labels:  metalsmith
streetsupport-web
Helping people facing homelessness across the UK to find services in their area, and connecting people who want to help to where it is needed most.
Stars: ✭ 21 (-8.7%)
Mutual labels:  metalsmith
metalsmith-jquery
A Metalsmith plugin to manipulate HTML via jQuery syntax
Stars: ✭ 13 (-43.48%)
Mutual labels:  metalsmith
markdown
A metalsmith plugin to render markdown files to HTML.
Stars: ✭ 58 (+152.17%)
Mutual labels:  metalsmith
metalsmith-convert
Convert images with imagemagick (via imagemagick-native).
Stars: ✭ 17 (-26.09%)
Mutual labels:  metalsmith
directus-metalsmith-snipcart
Lookbook web app with Directus' open source headless CMS, Metalsmith, Vue.js & Snipcart
Stars: ✭ 14 (-39.13%)
Mutual labels:  metalsmith
metalsmith-paths
Metalsmith plugin that adds file path values to metadata
Stars: ✭ 19 (-17.39%)
Mutual labels:  metalsmith
metalsmith-request
Metalsmith plugin to grab content from the web and expose the results to metadata
Stars: ✭ 12 (-47.83%)
Mutual labels:  metalsmith
metalsmith-imagemin
Metalsmith plugin to minify images
Stars: ✭ 17 (-26.09%)
Mutual labels:  metalsmith
remove
A Metalsmith plugin to remove files from the build
Stars: ✭ 19 (-17.39%)
Mutual labels:  metalsmith
Staticman
💪 User-generated content for Git-powered websites
Stars: ✭ 2,098 (+9021.74%)
Mutual labels:  metalsmith
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+9052.17%)
Mutual labels:  metalsmith
Metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,692 (+33343.48%)
Mutual labels:  metalsmith
metalsmith-babel
A Metalsmith plugin to compile JavaScript with Babel
Stars: ✭ 19 (-17.39%)
Mutual labels:  metalsmith
metalsmith
An extremely simple, pluggable static site generator.
Stars: ✭ 7,721 (+33469.57%)
Mutual labels:  metalsmith
metalsmith-code-highlight
Metalsmith plugin for syntax highlighting code with HTML
Stars: ✭ 14 (-39.13%)
Mutual labels:  metalsmith
headings
A Metalsmith plugin that extracts headings from HTML files and attaches them to the file's metadata.
Stars: ✭ 22 (-4.35%)
Mutual labels:  metalsmith

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:

$ yarn add metalsmith-html-minifier

How do I use this thing?

A quick example:

const Metalsmith   = require("metalsmith");
const 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:

const Metalsmith   = require("metalsmith");
const htmlMinifier = require("metalsmith-html-minifier");
Metalsmith(__dirname)
    .use(htmlMinifier({
        pattern: "**/*.html",
    }))
    .build();

You can also pass an array of globs to match filenames:

const Metalsmith   = require("metalsmith");
const htmlMinifier = require("metalsmith-html-minifier");
Metalsmith(__dirname)
    .use(htmlMinifier({
        pattern: ["**/*.html", "**/*.xhtml"],
    }))
    .build();

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

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

Options

See Options Quick Reference for a full reference. The options passed to the plug-in are merged with the defaults 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.

Option Description
collapseBooleanAttributes Omit attribute values from boolean attributes
collapseWhitespace Collapse white space that contributes to text nodes in a document tree
removeAttributeQuotes Remove quotes around attributes when possible
removeComments Strip HTML comments
removeEmptyAttributes Remove all attributes with whitespace-only values
removeRedundantAttributes Remove 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].