stylus-versioned-urls

0.0.1 • Public • Published

stylus-versioned-urls NPM version Build Status

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'
])

Dependents (0)

Package Sidebar

Install

npm i stylus-versioned-urls

Weekly Downloads

3

Version

0.0.1

License

none

Last publish

Collaborators

  • goodeggs-admin
  • hurrymaplelad