grunt-bust

Insert MD5 hash of file into urls referencing that file

grunt-bust

replace urls with bustable urls

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-bust --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-bust');

In your project's Gruntfile, add a section named bust to the data object passed into grunt.initConfig().

grunt.initConfig({
  bust: {
    options: {
        bustable: [ '**/*.html' ],
        regexes: [{
            filepath: 'js/index.js',
            regex: /(require\(\['index)/g
        }],
        basePath: 'test/fixtures/',
        prepend: 'bust',
    },
    your_target: {
          files: [{
              expand: true,     // Enable dynamic expansion. 
              src: ['test/fixtures/require.html'], // Actual pattern(s) to match. 
              dest: 'tmp/'   // Destination path prefix. 
          }]
    },
  },
})

Type: Array

An Array of string file path globs matching the files that might have a url referencing it.

Type: Array Default value: []

an array of objects mapping pattern to filepath

Type: String Default value: 'cbuster-'

A string to insert before the md5 inserted into urls

Type: String Default value: ''

Remove basepath from files you are trying to match against.

Type: String Default value: ''

filepaths will be converted to be relative to baseDir

In this example, the default options replace all references to all files in html files.

grunt.initConfig({
  bust: {
    options: {
    },
    files: [{
        expand: true,     // Enable dynamic expansion. 
        src: [
            '**/*.html'
        ],
        dest: '../dist/'   // Destination path prefix. 
    }]
  }
})

In this example, regexes are used to insert a cachebuster after a require.js include. All cachebusters are prepended with bust instead of cbuster-, and only js files are replaced.

grunt.initConfig({
  bust: {
    options: {
        regexes: [{
            filepath: 'js/index.js',
            regex: /(require\(\['index)/g //']) 
        }],
        basePath: 'app/',
        prepend: 'bust',
        bustable: [ 'js/**/*.js' ]
    },
    files: [{
        expand: true,     // Enable dynamic expansion. 
        src: [
            '**/*.html',
            '!node_modules/**/*.html'
        ],
        dest: '../dist/'   // Destination path prefix. 
    }]
  }
})

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

(Nothing yet)