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

asset-rev

v0.2.0

Published

Append hash to assets and updates references in each file specified

Downloads

186

Readme

asset-rev

Append hash to assets and updates references in each file specified

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev asset-rev

or

yarn add -D asset-rev

Usage

With npm scripts you can do:

{
  "scripts": {
    "rev": "asset-rev dist 'scripts/**/*.* images/**/*.*'"
  }
}

or with node

const rev = require('asset-rev');

const workingDir = 'dist';
const patterns = ['scripts/**/*.*', 'images/**/*.*'];

rev(workingDir, patterns);

API

npm scripts

asset-rev [workingDir] [patterns] [options]
  • workingDir: Relative to your project root, specifies where the script should look for your patterns and also defines that all files in this folder will have their references of the rev'd files updated.
  • patterns: String of glob patterns for files to be rev'd inside the workingDir. You can specify multiple globs separated by a space and encapsulated by single quotes, 'test/*.* test1/*.*'.
  • options:
    • --contenthash: By default the hash generated will be random every time, if you would instead prefer the hash to be generated based on content then you can pass in this variable.
    • --foldermatch: By default this is set to true, asset-rev will only hash strings it comes across if it is a complete 1 - 1 match when including the directory path relative to the workingDir. It it preferred to keep this option enabled as you may come into issues if you have two files with the same name but in different folders, though if you have a path that is constructed through string concatenation then this can serve as an alternative.

Node

rev(workingDir, patterns).then(() => {
  // ...
}).catch(err => {
  // ...
});
  • workingDir: Much like for the command line usage relative to your project root, this will be a string of where the script should look for your patterns and also defines that all files in this folder will have their references of the rev'd files updated.
  • patterns: This accepts an array of strings of glob patterns for the files to be rev'd inside the workingDir.
  • options: typeof Object
    • contenthash: Boolean variable that when passed in will generate the hash based on content, by default hashes are random each time.
    • foldermatch: Boolean variable that when passed in will take the full path into consideration for string matches

Caveat

When specifying your globs, be careful that if your patterns match a dir name, that dir name will be rev'd. Whether or not this is desirable is up to you.

Inspiration

I created this little script as I wanted an alternative to grunt-usemin, but without grunt. I searched for quite a while and wasn't able to find a solid alternative that makes use of npm scripts so I decided to write my own.

License

MIT