Giter VIP home page Giter VIP logo

grunt-filerev's Introduction

grunt-filerev Build Status

Static asset revisioning through file content hash

Getting Started

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, install this plugin with this command:

$ npm install --save-dev grunt-filerev

Overview

This task will revision your files based on its contents. You should then set the files to expire far into the future for better caching and it will only update when it changes.

Example

grunt.initConfig({
  filerev: {
    options: {
      algorithm: 'md5',
      length: 8
    },
    images: {
      src: 'img/**/*.{jpg,jpeg,gif,png,webp}'
    }
  }
});

Options

options.algorithm

Type: string
Default: 'md5'

algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha1', 'md5', 'sha256', 'sha512', etc. On recent releases, openssl list-message-digest-algorithms will display the available digest algorithms.

options.length

Type: number
Default: 8

The number of characters of the file hash to prefix the file name with.

options.copy

Type: Boolean
Default: null

Flag controlling whether the original file is copied or moved. If not set, other parameters, such as setting a destination control the behaviour.

options.process(basename, name, extension)

Type: function
Default: null
Returns: string

A function to process the revised file name and return back the new file name.

basename

Type: string

The basename of the file.

name

Type: string

Name with the revision suffixed.

extension

Type: string

The file extension.

Destination

It will overwrite the src files if you don't specify a dest:

filerev: {
  images: {
    src: ['img1.png', 'img2.png'],
    dest: 'tmp'
  }
}

Summary

The task keeps track of all files created and its sources in a summary that is exposed through the grunt.filerev.summary object. It can be used to replace references to the revved files or debugging purposes. The key of the object is the original filename, the value is the new revved path.

For a configuration like this

filerev: {
  images: {
    src: ['img1.png', 'img2.png'],
    dest: 'tmp'
  }
}

the content grunt.filerev.summary could look like that:

{
  'img1.png': 'tmp/img1.59bcc3ad.png',
  'img2.png': 'tmp/img2.060b1aa6.png'
}

Source Maps

The task will ensure that any source map for .css or .js file is revisioned with the same revision as the source file.

For example, js/main.js revisioned to js/main.9d713a59.js will also have js/main.js.map revisioned to the same hash js/main.9d713a59.js.map.

License

BSD license and copyright Google

grunt-filerev's People

Contributors

sindresorhus avatar sleeper avatar kevva avatar passy avatar stephanebachelier avatar nelsonpecora avatar arthurvr avatar callmevlad avatar aurelioderosa avatar geedew avatar eddiemonge avatar eirslett avatar ludow avatar maheshm avatar pavelvanecek avatar murphybob avatar sebdeckers avatar xhmikosr avatar facboy avatar hemanth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.