下述给出了常用Grunt插件,并列举了部分插件示例:
Gruntfile.js 骨架
'use strict';
module.exports = function(grunt){
var config = {
path: __dirname,
src: __dirname + '/test/src',
dest: __dirname + '/test/dest'
};
grunt.initConfig({
config: config,
pkg: grunt.file.readJSON('package.json')
});
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
示例:将1.html文件中的var requestAddress = "";
替换为var requestAddress = "http://blog.csdn.NET/ligang2585116";
// grunt-text-replace 使用字符串、正则、函数替换文本内容
replace: {
requestAddress: {
src: ['<%= config.src %>/1.html'],
overwrite: true,
replacements: [{
from: 'var requestAddress = "";',
to: 'var requestAddress = "http://blog.csdn.net/ligang2585116";'
}]
}
}
示例:给1.js增加md5戳,并替换1.html对1.js引用
filerev: {
options: {
algorithm: 'md5',
length: 8
},
js: {
src: '<%= config.src %>/1.js'
}
},
filerev_replace: {
options: {
assets_root: '<%= config.src %>/',
views_root: '<%= config.src %>/'
},
js: {
src: '<%= config.src %>/1.html'
}
}
grunt.registerInitTask("js-md5", "add md5 for js", ['filerev:js', 'filerev_replace:js']);
来源自:http://blog.csdn.net/ligang2585116/article/details/53790043