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

grunt-hashly

v0.4.0

Published

Renames static files with a hashcode for cache busting

Downloads

29

Readme

grunt-hashly Build Status

grunt-hashly is a grunt binding for hashly, which is a build-time tool that enables cache-busting for static files (images, JavaScript, CSS, etc).

Getting Started

This plugin requires Grunt ^0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-hashly --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-hashly');

hashly task

Run this task with the grunt hashly command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

This task offers all the same options as the hashly command line interface, so please refer to the documentation for advanced configuration.

basePath

Type: String (required)

Sets the base path to use (from which all paths will be root-relative) when generating the hashly manifest file.

targetPath

Type: String Default: basePath

Optionally specify a target directory to which hashed files and the manifest should be copied. If not specified, files are hashed in-place.

manifestFormat

Type: String Default: json

Optionally specify the format of the manifest file. Currently supports "json", "json-object" (json with original path as key) or "tab" (tab delimited). Default is "json".

manifestPath

Type: String Default: json

Specifies a path for the manifest file. If not specified, the manifest is named "manifest.{ext}" and is placed in the destination directory root.

processCss

Type: Boolean Default: false

If true, image paths in CSS files are rewritten to point to the hashed versions of the images. This ensures that when images change, the url of the CSS that references them also changes.

include

Type: String

Optionally specify a comma-delimited list of globbing patterns to use to include files to be hashed/copied.

exclude

Type: String

Optionally specify a comma-delimited list of globbing patterns to use to exclude files from being hashed/copied.

passthrough

Type Boolean Default false

A globbing expression. Any matching files will be copied as-is to the destination folder. Has no effect if the destination is the same as the source.

amend

Type Boolean Default False

Instructs hashly to amend an existing manifest, where it would normally delete and recreate it from scratch. This is useful for incrementally adding to a large filesystem.

quickhash

Type Boolean Default False

Use the file size for binary files instead of the file contents. This makes processing large binary files extremely quick, though at a (extremely slight) risk that a hashcode will not change when a file is updated.

hashLength

Type Integer Default 32

Specifies the length of the hash used when renaming files. Default is 32 characters.

renameFormat

Type: String

Specifies the format to use when renaming files. Variables are specified using curly brackets (e.g., {variable}). Any other characters are directly included in the output.

Available variables include:

  • {basename}: the base filename without extension
  • {hash}: the hash value
  • {extname}: the file extension

Default is "{basename}-hc{hash}{extname}".

continueOnError

Type Boolean Default False

Ignore errors. Otherwise, hashly will abort on the first error.

continueOnPluginError

Type Boolean Default False

Ignore errors from plugins. Takes precedence over continueOnError.

disabledPlugins

Type: String

Semicolon-delimited list of plugin names that should be disabled.

cleanOldDays

Type Integer Default 0

Deletes files that aren't in the manifest and are older than the specified number

sourcemapIncludePath

Type: Boolean Default: True

Include the absolute path to the source map in the JS/CSS source, relative to base-dir.

sourcemapURLPrefix

Type: String

A URL prefix to apply to the source map tag, if it is not in the same location as the source.

Usage examples

Basic usage

This configuration will output all hashed files and the manifest in place.

grunt.initConfig({
  hashly: {
    my_target: {
      basePath: "./staticFiles"
    }
  }
});

Setting a targetPath

This configuration will output all hashed files and the manifest in the specified target directory.

grunt.initConfig({
  hashly: {
    my_target: {
      basePath: "./staticFiles",
      targetPath: "./staticFilesProcessed"
    }
  }
});

Setting the manifest format to 'tab'

This configuration will output all hashed files and the manifest in place, with the manifest in tab-delimited format.

grunt.initConfig({
  hashly: {
    my_target: {
      basePath: "./staticFiles",
      options: {
        manifestFormat: "tab"
      }
    }
  }
});

Setting an exclusion pattern

This configuration will exclude any *.pdf files from being hashed.

grunt.initConfig({
  hashly: {
    my_target: {
      basePath: "./staticFiles",
      options: {
        exclude: "*.pdf"
      }
    }
  }
});