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

gulp-filerev-replace

v1.0.0

Published

Rev and replace files according to their mutual dependencies

Downloads

5

Readme

gulp-filerev-replace

Rev and replace files according to their mutual dependencies. This plugin accepts a stream containing all the files to filerev and/or replace. It will detect which files reference which files, and then transform the files accordingly. For example, if we filerev and replace these files:

index.html: <img src="/loader.gif" /> <link href="/styles.css" type="text/css" />
loader.gif
styles.css: body {background: url("/loader.gif")}

The process will be the following (hashes are made up for the example):

  1. Filerev loader.gif into loader-11111111.gif
  2. Replace /loader.gif in index.html and styles.css
  3. Filerev styles.css into styles-22222222.css
  4. Replace /styles.css in index.html
  5. Filerev index.html into index-33333333.html

Notice that loader.gif is filereved first, since it is referenced the most, then styles.css and finally index.html. The resulting stream will be:

loader-11111111.gif
styles-22222222.css: body {background: url("/loader-11111111.gif")}
index-33333333.html: <img src="/loader-11111111.gif" /> <link href="/styles-22222222.css" type="text/css" />

Usage

var filerevReplace = require('gulp-filerev-replace');

// Include all files to filerev and/or replace, making sure the base is correct
gulp.src('/mysite/**/*', {base: '/mysite'})
  .pipe(filerevReplace({
    filerev: ['assets/**/*'], // Select the files to filerev
    replace: ['views/**/*'],  // Select the files to replace
    base:    'assets'         // Filerevved files are served from the assets directory by the web server
  }))
  ...

Options

  • filerev: minimatch pattern to filter the files to filerev.
  • replace: minimatch pattern to filter the files to replace.
  • base: Directory from where the files are served by the web server. Optional, defaults to the file's base;

Manifest

A second plugin is also available that adds a new file to the stream. This file contains a JSON list of all files that were filereved.

Usage

var filerevReplace = require('gulp-filerev-replace');

// Include all files to filerev and/or replace, making sure the base is correct
gulp.src('/mysite/**/*', {base: '/mysite'})
  .pipe(filerevReplace({
    filerev: ['assets/**/*'], // Select the files to filerev
    replace: ['views/**/*'],  // Select the files to replace
    base:    'assets'         // Filerevved files are served from the assets directory by the web server
  }))
  .pipe(filerevReplace.addManifest({path: 'assets/filerev.json'}))
  ...

The example above would add a new file in the stream, with path assets/filerev.json, containing something like:

{
  "assets/loader.gif": "assets/loader-11111111.gif",
  "assets/styles.css": "assets/styles-22222222.css"
}

Options

options is an object containing the vinyl file options to use for the manifest file. It defaults to:

  • path: filerev-replace-manifest.json

TODO

  • Try to break this into simpler plugins...
  • Handle null files
  • Handle relative paths in current directory?
  • Document matched patterns