Skip to content
This repository has been archived by the owner. It is now read-only.

oaeproject/grunt-ver

master
Switch branches/tags
Code
This branch is 7 commits ahead, 7 commits behind chrisdanford:master.
Contribute

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

grunt-ver

0.1.x was the last version of this plugin that supported Grunt 0.3.x.

A Grunt 0.4 multi-task that does 3 things:

  1. Renames files in-place to add a version tag that a hash of the contents.

  2. (optional) Updates references to the renamed files. Replacement is done in-place using a naive find/replace of the original basename of the file (e.g. 'logo.png') to the versioned basename (e.g. 'logo.abc123.png'). You can specify which files to replace over via the 'references' option.

  3. (optional) Writes a json file containing version information. This can be consumed by an external application.

Versioning and replacements are done in one or more 'phases'. This is necessary when you update file references inside of files that also need to be versioned. For example: CSS files refer to versioned image files, but the CSS files themselves need to be versioned. The CSS files cannot be versioned until the references have been updated because versioning depends on the file contents being finalized.

Getting Started

Install the module with: npm install grunt-ver

Then load it from your grunt.js file:

grunt.loadNpmTasks('grunt-ver');

In your grunt.js file, add the follow task entry:

version: {
  myapp: {
    phases: [
      {
        files: [
          'images/*.png'
        ],
        references: [
          'css/*.css'
        ]
      },
      {
        files: [
          'css/*.css',
          'js/*.js'
        ]
      }
    ],
    version: 'build/version.json'
  }
}

Force Version

You can force the version string to all files to a particular value using the forceversion option. This is useful for development environments where stable file names are helpful for debugging and where cache busting isn't an issue.

version: {
  myapp: {
    forceVersion: "dev"
    phases: [
      {
        files: [
          'css/*.css',
          'js/*.js'
        ]
      }
    ],
    version: 'build/version.json'
  }
}

After the task is run, all files will have version tags, the CSS files will refer to the versioned images, and build/version.json will exist.

License

Copyright (c) 2012 Chris Danford Licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%