stylus-versioned-urls
v0.0.1
Published
Stylus plugin to version urls in built css
Downloads
3
Readme
stylus-versioned-urls
Stylus plugin to version urls in built css.
This plugin doesn't generate versioned urls, it assumes you've already done that. It takes a map of unversioned to versioned urls and translates unversioned urls in the stylus source to versioned urls in the css output.
Installation
npm install stylus-versioned-urls
Usage
var stylus = require('stylus'),
versionedUrls = require('stylus-versioned-urls')
versions = {
'/fonts/sans.woff': '/fonts/sans.123.woff'
'/fonts/serif.woff': '/fonts/serif.456.woff'
};
stylus(css)
.use(versionedUrls(versions))
.render(function(err, output) {
console.log(output)
})
With Grunt
Combine with grunt-contrib-stylus and grunt-assets-versioning to version and build CSS:
var stylusVersionedUrls = require('stylus-versioned-urls')
grunt.loadNpmTasks('grunt-contrib-stylus')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-assets-versioning')
grunt.initConfig({
versionManifest: {},
assets_versioning: {
images: {
expand: true,
cwd: 'public/',
src: ['**/*.jpg', '**/*.png'],
dest: 'versioned/',
options: {
use: 'hash',
hashLength: 8,
multitask: 'copy',
output: 'build/version_manifest.json'
}
}
},
stylus: {
all: {
src: 'src/**/*.styl',
dest: 'public/css/'
ext: '.css'
options: {
use: [
function() {
return stylusVersionedUrls(grunt.config('versionManifest'))
}
]
}
}
}
})
grunt.registerTask('loadVersionManifest', function() {
var memoryManifest = grunt.config('versionManifest'),
fileManifest = grunt.file.readJSON('build/versionManifest')
fileManifest.forEach(function(file) {
memoryManifest[file.path] = file.revved_path
})
})
grunt.registerTask('default', [
'assets_versioning',
'loadVersionManifest',
'stylus'
])