npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

metalsmith-html-unused

v2.0.1

Published

A Metalsmith plugin to exclude files unused in HTML.

Downloads

41

Readme

metalsmith-html-unused

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

A Metalsmith plugin to exclude resources that aren't referenced in HTML files.

Removing unreferenced files such as JavaScript, CSS, images, and documents helps optimize your build output.

Installation

npm install --save metalsmith-html-unused

JavaScript Usage

const Metalsmith = require('metalsmith');
const unused     = require('metalsmith-html-unused');

Metalsmith(__dirname)
    .use(unused({
        pattern: '**/*.@(css|js)'
        // other options here
    }))
    .build((err) => {
        if (err) {
            throw err;
        }
    });

Options

pattern (required)

Type: string

A micromatch glob pattern for files to consider for removal.

Example: "**/*.@(css|js|bmp|gif|jpg|jpeg|png|svg|tif|tiff|webp)"

ignore (optional)

Type: string

A micromatch glob pattern for files to exclude from removal. If no pattern is defined then no files will be ignored.

html (optional)

Type: string Default: "**/*.html"

A micromatch glob pattern to find HTML files.

attributes (optional)

Type: string[] Default: ['href', 'src', 'data-src', 'content']

An array of HTML attributes that link to files.

Example

Given the config:

{
    "pattern": "**/*.@(css|js|png)",
    "ignore": "**/logo.png"
}

And a file tree:

.
├── index.html
└── static
    ├── css
    │   ├── bootstrap.min.css
    │   └── fontawesome.all.min.css
    ├── img
    │   └── logo.png
    └── js
        ├── bootstrap.min.js
        └── popper.js

And index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="static/css/bootstrap.min.css">
    </head>
    <body>
        <script src="static/js/bootstrap.min.js"></script>
    </body>
</html>

Both static/js/fontawesome.all.min.css and static/js/popper.js would be excluded from build output because they are not referenced, and static/img/logo.png would persist because it was ignored. The final file tree would be:

.
├── index.html
└── static
    ├── css
    │   └── bootstrap.min.css
    ├── img
    │   └── logo.png
    └── js
        └── bootstrap.min.js

Changelog

Changelog