Skip to content
PostCSS plugin for css url revision
Branch: master
Clone or download
Latest commit 07f7e4c May 7, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Add remote url test case May 4, 2017
.eslintrc Supress eslint error May 7, 2017
.gitignore it works well Aug 21, 2015
.npmignore Clean .npmignore Sep 23, 2015
.travis.yml Update .travis.yml May 7, 2017
CHANGELOG.md Release v2.0.0 May 7, 2017
LICENSE first init Aug 20, 2015
README.md Update postcss to 6.0 May 7, 2017
gulpfile.js first init Aug 20, 2015
index.js Remove bluebird dependency May 7, 2017
package.json Release v2.0.0 May 7, 2017

README.md

postcss-urlrev

PostCSS plugin for css url revision, inspired by postcss-url

Build Status Coverage Status

/* Input example */
.foo {
    background: url(images/test.png) 0 0 no-repeat;
}
/* Output example */
.foo {
    background: url(images/test.png?v=e19ac7dee6) 0 0 no-repeat;
}

Install

For postcss 6.x

npm install --save-dev postcss-urlrev

and for postcss 5.x

npm install --save-dev postcss-urlrev@1.x

Usage

var urlrev = require('postcss-urlrev');
postcss(urlrev({ /* options */ }))

Options

relativePath

Type: string
Default: the css file's folder

The relativePath is used to calculate the absolute path of the url resource. By default, the value is the folder path of the css source file. You should set this value based on your environment.

absolutePath

Type: string
Default: undefined

The absolutePath is used to calculate the absolute path of the url resources that have an absolute path, f.ex. /images/test.png. If absolutePath is not set, absolute url's will be skipped, as the full path to the resource cannot be resolved.

includeRemote

Type: boolean
Default: false

If you set it to true, it will handle the remote url, request the remote resource and calculate the md5 hash.

hashFunction(filename, baseName)

Type: function
Default: undefined

If specified, it will use the hashFunction to generate hash strings.

The function accepts two parameters:

  • filename: the absolute file path. (e.g. /path/to/test.png)
  • baseName: the base name of the file. (e.g. test.png)

replacer(url, hash)

Type: function
Default: defaultReplacer(url, hash)

It will receive the url and hash as its parameter, you can specify a function to handle the url manually.

A replacer example:

function replacer(url, hash) {
    return url + '?' + hash;
}

hashLength

Type: number
Default: 10

The length of the hash string, the default value is 10. That's enough!

Changelog

License

MIT

You can’t perform that action at this time.