A node package for css url versioner
npm install --save-dev css-url-versioner
var cssVersioner = require('css-url-versioner');
fs.readFile('test/css/test.css', 'utf8', function (err, data) {
var newCss = cssVersioner({
content: data
});
console.log(newCss.output);
});
var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';
var cssVersioned = cssVersioner({
content: data
});
console.log(cssVersioned.output);
//logs: '.some_selector{background-image: url("img/sprite.png?v=2014111");}';
Required: true
Here go the css content we want versioning
{content: '.some_selector{background-image: url("img/sprite.png");}'}
Default: v
Here go the variable of our version, for '?myVariable=yyyymmdd'
{variable: 'myVariable'}
Default: yyyymmdd
Here you go a custom version if you so desire, but if we do not put this key, then the default version will be the current date.
{version: '0.0.2'}
Default: false
If we want that version to be our short version of last commit in git, configured 'lastcommit' to true.
{lastcommit: true}
var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';
var cssVersioned = cssVersioner({
content: data,
lastcommit: true
});
console.log(cssVersioned.output);
//logs: '.some_selector{background-image: url("img/sprite.png?v=dc31e29");}';
var cssVersioner = require('css-url-versioner');
var data = '@font-face{
font-family: 'gotham';
src: url("fonts/gotham.svg#gotham") format('svg');
}';
var cssVersioned = cssVersioner({
content: data,
variable: 'myVersion'
lastcommit: true
});
console.log(cssVersioned.output);
//logs: '@font-face{ font-family: 'gotham'; src: url("fonts/gotham.svg?myVersion=dc31e29#gotham") format('svg'); }';
var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';
var cssVersioned = cssVersioner({
content: data,
version: Math.random()
});
console.log(cssVersioned.output);
//logs: '.some_selector{background-image: url("img/sprite.png?v=0.82140917");}';