PostCSS plugin for css url revision, inspired by postcss-url
/* 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;
}For postcss 8.x
npm install --save-dev postcss-urlrevand for postcss 6.x
npm install --save-dev postcss-urlrev@2.xvar urlrev = require('postcss-urlrev');
postcss(urlrev({ /* options */ }))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.
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.
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.
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)
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;
}Type: number
Default: 10
The length of the hash string, the default value is 10. That's enough!