Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including metalsmith-fingerprint-ignore with all npm packages installed. Try it out:

var metalsmithFingerprintIgnore = require("metalsmith-fingerprint-ignore")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-fingerprint-ignore v2.0.0

A fork of metalsmith-fingerprint that discards the original file

metalsmith-fingerprint-ignore

npm Build Status

A fork of metalsmith-fingerprint that discards the original file

This plugin fingerprints your files for easy and reliable cache-busting. Since you're not going to use the original, this fork discards it by default (but still allows you to keep it if you want to).

This plugin normalizes paths on windows using slash so that in most cases builds will work on both windows and *nix without any changes to the paths. Check the docs for slash for more details.

Installation

npm install metalsmith-fingerprint-ignore

Example

Say you want to fingerprint the file css/index.css:

Metalsmith(__dirname)
  .use(fingerprint({ pattern: 'css/index.css' }))
  .use(template({ engine: 'handlebars' }))
  .build()

The plugin does three things:

  1. create a duplicate of index.css with a fingerprinted filename
  2. create a fingerprint object on the Metalsmith metadata
  3. Discard the original index.css file

The fingerprint object is accessible from the Handlebars template:

<link href="{{ fingerprint.[css/index.css] }}" rel="stylesheet" type="text/css" />

And the template renders the fingerprinted filename:

<link href="css/index-724af9dd72a48c18dd570790c2445fb4.css" rel="stylesheet" type="text/css" />

Options

You can pass options to metalsmith-fingerprint-ignore with the Javascript API or CLI. The options are:

  • pattern: a pattern to filter source files (required)
  • keep: keep source file, false by default (optional)

pattern

String|Array<String>: A pattern to filter source files. The path is relative to your source. Required.

{
  "plugins": {
    "metalsmith-fingerprint-ignore": {
      "pattern": "css/index.css"
    }
  }
}

keep

Boolean: Keep the original file. Setting it to true will keep the original file and create a fingerprinted version as well. Default false. Optional.

{
  "plugins": {
    "metalsmith-fingerprint-ignore": {
      "pattern": "css/index.css",
      "keep": "true"
    }
  }
}

Origins

Metalsmith fingerprint does not discard the original file after fingerprinting. So when fingerprinting a large collection of files you'll have to manually ignore them all. Unfortunately the only predictable difference between the original and the fingerprinted file is the dash before the fingerprint.

An issue was opened to address this, but closed as wontfix. So this fork is based on the PR by callum, which can be used by those who would still like this functionality.

Thanks to:

License

MIT.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free