No description, website, or topics provided.
JavaScript
Clone or download
Pull request Compare This branch is 7 commits ahead, 7 commits behind chrisdanford:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tasks
test
.gitignore
Gruntfile.js
LICENSE-MIT
README.md
package.json

README.md

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.