Git Product home page Git Product logo

metalsmith-html-minifier's Introduction

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.

metalsmith-html-minifier's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar jacobmillward avatar michel-kraemer avatar whymarrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

metalsmith-html-minifier's Issues

Getting stuck

I'm running the plugin over about 100+ html pages. Is there a way to view the progress? It seems to just get stuck when I start a build. Any thoughts?

Update Jest

Update the Jest version used by the project

Update Jest

The version of Jest used here is kinda old and there is a single? breaking change preventing a version bump because it fails a test.

html-minifier as a peer dependency?

Hey thanks for this project! Would you be open at making html-minifier a peer dependency instead of a direct dependency?

The benefit of making it a peer dependency is that users can upgrade html-minifier minor versions without bugging you to upgrade your own lib.

Let me know if that's OK and Ill open a PR

Remove Babel

If the project can drop Node v4 support, Babel shouldn't be needed. (Babel is currently only used to allow for default arguments.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.