# node-sass-cache-busted-url

> Custom Sass function to replace URLs in CSS with cache busted URL

Latest version **0.0.1** (published 2015-06-21) · LGPLv3 license · 0 weekly downloads

## Install

```sh
npm install node-sass-cache-busted-url
pnpm add node-sass-cache-busted-url
yarn add node-sass-cache-busted-url
bun add node-sass-cache-busted-url
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-06-21 |
| First published | 2015-06-21 |
| Weekly downloads | 0 |
| License | LGPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | KITAITI Makoto |
| Maintainers | kitaitimakoto |
| Keywords | Sass |

## Links

- npm: https://www.npmjs.com/package/node-sass-cache-busted-url
- Repository: https://github.com/KitaitiMakoto/node-sass-cache-busted-url
- Issues: https://github.com/KitaitiMakoto/node-sass-cache-busted-url/issues
- npm.io page: https://npm.io/package/node-sass-cache-busted-url

## Dependencies (1)

- [node-sass](https://npm.io/package/node-sass.md) ^3.2.0

## Recent versions

- 0.0.1 (latest) — 2015-06-21

## README

node-sass-cache-busted-url
==========================

Sass custom function to replace URLs with ones with cache buster strings. Usable in node-sass.

USAGE
-----

Let case as below:

```scss
// example.scss

body {
  background: cache-busted-url("/images/bg.png") no-repeat;
}
```

```json
// cache-busters.json
// expected to generate by programs like gulp-rev

{
  "/images/bg.png": "/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png",
  ...
}
```

### JavaScript API ###

```javascript
var sass = requrie("node-sass");
var cacheBustedUrl = require("node-sass-cache-busted-url");

// Generate cache buster object which has url as key and cache-busted url as value
var cacheBusters = require(./cache-busters.json);

// Determine function signature used in Sass file
var functionSignature = "cache-busted-url($url)";

// Apply cache busters
var bustersDefinedBuster = cacheBustedUrl.bind(null, cacheBusters);

// Render CSS with pass `functions` option
var compiled = sass.renderSync({
  file: "./example.scss",
  functions: {
    functionSignature: bustersDefinedBuster
  }
});
console.log(compiled.css.toString());
// body {
//   background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }
```

### Command-line interface ###

`node-sass` accepts `functions` options to specify file which defines Sass custom functions.

At CLI, specify path to file which defines URL-cache busted URL mapping by environment variable `CACHE_BUSTERS_PATH`.

```
$ CACHE_BUSTERS_PATH=cache-busters.json \
  $(npm bin)/node-sass \
  --functions=$(npm root)/node-sass-cache-busted-url/custom-functions.js \
  example.scss
body {
  background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }

```

### Customize function name ###

As advanced usage of library, you can change the name of Sass custom function. Let's use it as `image-url` function:

```scss
// example.scss

body {
  background: image-url("/images/bg.png") no-repeat;
}
```

```json
// cache-busters.json

{
  "/images/bg.png": "/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png",
  ...
}
```

Then execute JavaScript. Note that the value of `functionSignature` is changed:

```javascript
var sass = requrie("node-sass");
var cacheBustedUrl = require("node-sass-cache-busted-url");

// Specify cache busters file
var cacheBusters = require(./cache-busters.json);

// Determine function signature used in Sass file
var functionSignature = "image-url($url)";

// Apply cache busters
var bustersDefinedBuster = cacheBustedUrl.bind(null, cacheBusters);

// Render CSS with pass `functions` options
var compiled = sass.renderSync({
  file: "./example.scss",
  functions: {
    functionSignature: bustersDefinedBuster
  }
});
console.log(compiled.css.toString());
// body {
//   background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }
```

LICENSE
-------

LGPLv3 or later. See LICENSE for details.

---
_Source: https://npm.io/package/node-sass-cache-busted-url · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
