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-revplace

v0.2.3

Published

Ultimate asset collector and rev-helper for gulp

Downloads

10

Readme

gulp-revplace

Simple helper for gulp-rev to fix all asset references. It works with relative urls too! By default it doesn't pass through assets that are not mentioned in source files. This plugin can be very useful in your build scenarios.

Install

$ npm install --save-dev gulp-revplace

Usage

Structure before rev:

.
├── build
└── static
    ├── images
    │   ├── cat.png
    │   ├── ghost.png
    │   ├── pumpkin.png
    │   └── zombie.png
    ├── index.html
    ├── scripts
    │   └── script.js
    └── styles
        └── style.css

script.js and style.css have references to all images. index.html have references to script.js and style.css.

/* style.css */
.first { background-image: url(/images/ghost.png); }
.second { background-image: url(/images/pumpkin.png); }
.third { background-image: url(../images/pumpkin.png); }
// script.js
(function() {
  var absoluteImageUrl = ASSET('/images/cat.png');
  var relativeImageUrl = ASSET('../images/cat.png');
  var absoluteImageUrl2 = ASSET('/images/zombie.png');
})();
<!-- index.html -->
<!doctype html>
<html>
<head>
  <link type="text/css" rel="stylesheet" href="styles/style.css"/>
  <script src="scripts/script.js"></script>
</head>
<body></body>
</html>

Let's make simple gulp task:

var gulp = require('gulp');
var rev = require('gulp-rev');
var revplace = require('gulp-revplace');
var es = require('event-stream');
var baseDir = 'static';

gulp.task('default', function () {
  return es.merge(
    gulp
      .src([baseDir + '/index.html'], { base: baseDir }),
    gulp
      .src([baseDir + '/*/**/*.*'], { base: baseDir })
      .pipe(rev())
  )
    .pipe(revplace())
    .pipe(gulp.dest('build'));
});

After execution file names will be changed and all references will be replaced.

.
├── build
│   ├── images
│   │   ├── cat-1ccfa741.png
│   │   ├── ghost-aa908d61.png
│   │   ├── pumpkin-5ca50d04.png
│   │   └── zombie-68157885.png
│   ├── index.html
│   ├── scripts
│   │   └── script-921c4eaf.js
│   └── styles
│       └── style-cc726e1b.css
└── static
    ├── images
    │   ├── cat.png
    │   ├── ghost.png
    │   ├── pumpkin.png
    │   └── zombie.png
    ├── index.html
    ├── scripts
    │   └── script.js
    └── styles
        └── style.css
/* style.css */
.first { background-image: url(/images/ghost-61865acd.png); }
.second { background-image: url(/images/pumpkin-cb05ce1b.png); }
.third { background-image: url(/images/pumpkin-cb05ce1b.png); }
// script.js
(function() {
  var absoluteImageUrl = ASSET('/images/cat-5d0e5c9b.png');
  var relativeImageUrl = ASSET('/images/cat-5d0e5c9b.png');
  var absoluteImageUrl2 = ASSET('/images/zombie-0dc22dba.png');
})();
<!-- index.html -->
<!doctype html>
<html>
<head>
  <title>Test page</title>
  <link type="text/css" rel="stylesheet" href="/styles/style-21373b83.css"/>
  <script src="/scripts/script-6bc83506.js"></script>
</head>
<body></body>
</html>

You can even change dirnames of your files. It will also work like a charm.

gulp.task('default', function () {
  return es.merge(
    gulp
      .src([baseDir + '/index.html'], { base: baseDir }),
    gulp
      .src([baseDir + '/*/**/*.*'], { base: baseDir })
      .pipe(rev())
  )
    .pipe(rename(function(path) {
      path.dirname = '';
    }))
    .pipe(revplace())
    .pipe(gulp.dest('build'));
});

Structure will be changed...

.
├── cat-5d0e5c9b.png
├── ghost-61865acd.png
├── index.html
├── pumpkin-cb05ce1b.png
├── script-6bc83506.js
├── style-21373b83.css
└── zombie-0dc22dba.png

...as well as file references.

/* style.css */
.first { background-image: url(/ghost-61865acd.png); }
.second { background-image: url(/pumpkin-cb05ce1b.png); }
.third { background-image: url(/pumpkin-cb05ce1b.png); }
// script.js
(function() {
  var absoluteImageUrl = ASSET('/cat-5d0e5c9b.png');
  var relativeImageUrl = ASSET('/cat-5d0e5c9b.png');
  var absoluteImageUrl2 = ASSET('/zombie-0dc22dba.png');
})();
<!-- index.html -->
<!doctype html>
<html>
<head>
  <title>Test page</title>
  <link type="text/css" rel="stylesheet" href="/style-21373b83.css"/>
  <script src="/script-6bc83506.js"></script>
</head>
<body></body>
</html>

API

revplace(options)

regex

Type: RegExp

Usage: Sets a custom regex to match on your files.

Default: /(?:url\(["']?(.*?)['"]?\)|src=["'](.*?)['"]|src=([^\s\>]+)(?:\>|\s)|href=["'](.*?)['"]|href=([^\s\>]+)(?:\>|\s)|ASSET\(['"](.+)['"]\))/g

You can define and use simple ASSET() function that only returns what it was given. Use it to declare asset urls in scripts. It'll help plugin to find all assets.

function ASSET(s) {return s;}

addPrefix

Type: String

Usage: Add prefix to replaced urls

Default: /

stripPrefix

Type: String

Usage: Strip prefix from initial urls

skipUnmentioned

Type: Boolean

Usage: If TRUE only assets that are mentioned in source files will be passed through stream. Source files are always passed.

Default: true

verbose

Type: Boolean

Usage: Activate verbose mode

License

MIT © Andrey Yamanov