grunt-web-stamp

0.5.1 • Public • Published

grunt-web-stamp

NPM version Downloads Build Status Build status Dependency status De vDependency status Coverage Status Built with Grunt

v0.5.0 has removed some options and fixed some bugs.

Add timestamp to the url path.It searches <img/>,<link/>,<script/> and url() to resolve every path and calculates timestamp to append to it.

Getting Started

This plugin requires Grunt ~0.4.5

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-web-stamp --save-dev

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

grunt.loadNpmTasks('grunt-web-stamp');

The "stamp" task

Overview

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

grunt.initConfig({
  stamp: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

baseDir

Type: String Default value: '.'

A string value that is indicating where the resource files are.

You can assign a function instead:

{
    baseDir:function(targetFilePath){return "static/";}
}

prefix

Type: String or Function Default value: ''

A string value that will be prepended to each url path.If it's defined as a function,real filepath will be passed in as the only parameter.Ex:

prefix:function(filepath){return /\.css$/.test(filepath)?'cdn_css':'cdn_js';}

pattern

Type: String or Function Default value: 'u|l|s|i'

A char sequence indicates which kinds of url should be handled.

  • 'i':<img/>
  • 'l':<link/>
  • 'u':url()
  • 's':<script/>

You can make any combination of them,they're case-sensitive.

You can assign a function instead.

{
    "pattern":function(filepath){
      return /\.html$/.test(filepath)?"l|i|s":"u";
    }
}

stampName

Type: String Default value: 't'

Query name for the timestamp.

algorithm

Type: String Default value: 'md5'

A crypto algorithm name.More available names are sha1,sha256 and sha512.

crypto

Alias for algorithm,but deprecated,it may be removed in the future.

changeFileName

Type: Boolean Default value: false

If set to true,stamp will be merged into filname instead of appended.Note that this will not rename the real file but copy it.

doCopy

Type: Boolean Default value: false Since: 0.5.0

Copy instead of rename when changeFileName is set to true.

regex

Type: Object Default value: {}

Custom search pattern defination.Ex:

regex: {
  '@': {
    pattern: /@([\w\/.]+)@/,
    index: 1,//filepath is in RegExp.$1
    whole: true //replace whole pattern,including the '@' on the both sides
  }
}

buildFileName

Type: Function Default value: ``

Custom filename building function.This is only useful when changeFileName is set to true.Ex:

function(filename, filext, stamp){
  return filename + '_' + stamp + '.' + filext;
}

fileStamp

Type: Function Default value: null

A function calculates a file's stamp,the file path is the parameter passed in ,Ex:

function(path){
  return md5(path) + Date.now();
}

Contributing

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.

Package Sidebar

Install

npm i grunt-web-stamp

Weekly Downloads

15

Version

0.5.1

License

none

Last publish

Collaborators

  • yinyongcom666