# gulp-rev-replace

> Rewrite occurences of filenames which have been renamed by gulp-rev

Latest version **0.4.4** (published 2018-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-rev-replace
pnpm add gulp-rev-replace
yarn add gulp-rev-replace
bun add gulp-rev-replace
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.4 |
| Published | 2018-02-03 |
| First published | 2014-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-rev-replace) |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 384 |
| Author | James K Nelson |
| Maintainers | jamesknelson |
| Keywords | gulpplugin, rev, revision, version, replace, asset |

## Links

- npm: https://www.npmjs.com/package/gulp-rev-replace
- Repository: https://github.com/jamesknelson/gulp-rev-replace
- Homepage: https://github.com/jamesknelson/gulp-rev-replace#readme
- Issues: https://github.com/jamesknelson/gulp-rev-replace/issues
- npm.io page: https://npm.io/package/gulp-rev-replace

## Dependencies (2)

- [through2](https://npm.io/package/through2.md) ^2.0.0
- [plugin-error](https://npm.io/package/plugin-error.md) ^0.1.2

## Recent versions

- 0.4.4 (latest) — 2018-02-03
- 0.4.3 — 2015-12-23
- 0.4.2 — 2015-06-12
- 0.4.1 — 2015-05-25
- 0.4.0 — 2015-02-27
- 0.3.4 — 2015-02-13
- 0.3.3 — 2015-01-28
- 0.3.2 — 2015-01-24
- 0.3.1 — 2014-08-15
- 0.3.0 — 2014-07-19
- 0.2.1 — 2014-06-17
- 0.2.0 — 2014-05-31
- 0.1.0 — 2014-04-09
- 0.0.1 — 2014-04-09

## README

[gulp](https://github.com/wearefractal/gulp)-rev-replace [![Build Status](https://travis-ci.org/jamesknelson/gulp-rev-replace.svg?branch=master)](https://travis-ci.org/jamesknelson/gulp-rev-replace)
================

Rewrite occurrences of filenames which have been renamed by gulp-rev

## Install

```bash
$ npm install --save-dev gulp-rev-replace
```


## Usage

Pipe through a stream which has both the files you want to be updated, as well as the files which have been renamed.

For example, we can use [gulp-useref](https://github.com/jonkemp/gulp-useref) to concatenate assets in an index.html,
and then use [gulp-rev](https://github.com/sindresorhus/gulp-rev) and gulp-rev-replace to cache-bust them.

```js
var gulp = require('gulp');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var useref = require('gulp-useref');
var filter = require('gulp-filter');
var uglify = require('gulp-uglify');
var csso = require('gulp-csso');

gulp.task("index", function() {
  var jsFilter = filter("**/*.js", { restore: true });
  var cssFilter = filter("**/*.css", { restore: true });
  var indexHtmlFilter = filter(['**/*', '!**/index.html'], { restore: true });

  return gulp.src("src/index.html")
    .pipe(useref())      // Concatenate with gulp-useref
    .pipe(jsFilter)
    .pipe(uglify())             // Minify any javascript sources
    .pipe(jsFilter.restore)
    .pipe(cssFilter)
    .pipe(csso())               // Minify any CSS sources
    .pipe(cssFilter.restore)
    .pipe(indexHtmlFilter)
    .pipe(rev())                // Rename the concatenated files (but not index.html)
    .pipe(indexHtmlFilter.restore)
    .pipe(revReplace())         // Substitute in new filenames
    .pipe(gulp.dest('public'));
});
```

It is also possible to use gulp-rev-replace without gulp-useref:

```js
var rev = require("gulp-rev");
var revReplace = require("gulp-rev-replace");
gulp.task("revision", ["dist:css", "dist:js"], function(){
  return gulp.src(["dist/**/*.css", "dist/**/*.js"])
    .pipe(rev())
    .pipe(gulp.dest(opt.distFolder))
    .pipe(rev.manifest())
    .pipe(gulp.dest(opt.distFolder))
})

gulp.task("revreplace", ["revision"], function(){
  var manifest = gulp.src("./" + opt.distFolder + "/rev-manifest.json");

  return gulp.src(opt.srcFolder + "/index.html")
    .pipe(revReplace({manifest: manifest}))
    .pipe(gulp.dest(opt.distFolder));
});
```


## API

### revReplace(options)

#### options.canonicalUris
Type: `boolean`

Default: `true`

Use canonical Uris when replacing filePaths, i.e. when working with filepaths
with non forward slash (`/`) path separators we replace them with forward slash.

#### options.replaceInExtensions
Type: `Array`

Default: `['.js', '.css', '.html', '.hbs']`

Only substitute in new filenames in files of these types.

#### options.prefix
Type: `string`

Default: ``

Add the prefix string to each replacement.

#### options.manifest
Type: `Stream` (e.g., `gulp.src()`)

Read JSON manifests written out by `rev`. Allows replacing filenames that were
`rev`ed prior to the current task.

#### options.modifyUnreved, options.modifyReved
Type: `Function`

Modify the name of the unreved/reved files before using them. The filename is
passed to the function as the first argument.

For example, if in your manifest you have:

```js
{"js/app.js.map": "js/app-98adc164.js.map"}
```

If you wanted to get rid of the `js/` path just for `.map` files (because they
are sourcemaps and the references to them are relative, not absolute) you could
do the following:

```js
function replaceJsIfMap(filename) {
    if (filename.indexOf('.map') > -1) {
        return filename.replace('js/', '');
    }
    return filename;
}

return gulp.src(opt.distFolder + '**/*.js')
    .pipe(revReplace({
        manifest: manifest,
        modifyUnreved: replaceJsIfMap,
        modifyReved: replaceJsIfMap
    }))
    .pipe(gulp.dest(opt.distFolder));
```

## Contributors

- Chad Jablonski
- Denis Parchenko
- Evgeniy Vasilev
- George Song
- Håkon K. Eide
- Juan Lasheras
- Majid Burney
- Simon Ihmig
- Vincent Voyer
- Bradley Abrahams


## License

[MIT](http://opensource.org/licenses/MIT) © [James K Nelson](http://jamesknelson.com)

---
_Source: https://npm.io/package/gulp-rev-replace · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
