The common grunt plug-ins are given below, and some examples of plug-ins are listed:
plug-in name |
Description |
GitHub Address |
Grunt-contrib-clean |
emptying files and folders |
Https://github.com/gruntjs/grunt-contrib-clean |
Grunt-contrib-copy |
Copying files and folders |
Https://github.com/gruntjs/grunt-contrib-copy |
Grunt-contrib-concat |
Connect, merge Files |
Https://github.com/gruntjs/grunt-contrib-concat |
Grunt-svgstore |
(SVG) to merge SVG from a specified folder |
Https://github.com/FWeinb/grunt-svgstore |
Grunt-csscomb |
(CSS) formatting |
Https://github.com/csscomb/grunt-csscomb |
Grunt-contrib-less |
(CSS) to compile less into CSS |
Https://github.com/gruntjs/grunt-contrib-less |
Grunt-contrib-cssmin |
(CSS file) compression |
Https://github.com/gruntjs/grunt-contrib-cssmin |
Grunt-contrib-uglify |
(JS file) compression |
Https://github.com/gruntjs/grunt-contrib-uglify |
Grunt-contrib-htmlmin |
(HTML file) compression |
Https://github.com/gruntjs/grunt-contrib-htmlmin |
Grunt-filerev |
File content Hash (MD5) |
Https://github.com/yeoman/grunt-filerev |
Grunt-filerev-replace |
Replace a file reference by Grunt-filerev |
Https://github.com/solidusjs/grunt-filerev-replace |
Grunt-text-replace |
(text file) Use string, Regular, function to replace content |
Https://github.com/yoniholmes/grunt-text-replace |
Grunt-html-build |
(HTML file) Add JS, CSS, template references, remove debug code |
Https://github.com/spatools/grunt-html-build |
Grunt-autoprefixer |
Add prefix dependent can I use database |
Https://github.com/nDmitry/grunt-autoprefixer |
Grunt-parallel |
Running commands and tasks in parallel |
Https://github.com/iammerrick/grunt-parallel |
Grunt-contrib-watch |
File Changes Run task |
Https://github.com/gruntjs/grunt-contrib-watch |
Load-grunt-tasks |
Use a wildcard multibyte to load all tasks |
Https://github.com/sindresorhus/load-grunt-tasks |
Time-grunt |
Displays the execution time of the running task |
Https://github.com/sindresorhus/time-grunt |
Gruntfile.js skeleton
' use strict ' ; Module.exports = function (grunt) { //configuration information var config = {path: __d Irname, src: __dirname + '/test/src ' , dest: __dirname + '/test/dest ' }; Grunt.initconfig ({config:config, Pkg:grunt.file.readJSON ( ' Package.json ' ) }); /* load all plugins */ require ( ' load-grunt-tasks ' ) (grunt); /* count individual task execution times */ require ( ' Time-grunt ' ) (grunt);};
Example : Replacing a 1.html file with a var requestAddress = "";
var requestAddress = "http://blog.csdn.net/ligang2585116";
// grunt-text-replace 使用字符串、正则、函数替换文本内容// grunt.initConfig({})中增加Taskreplace: { requestAddress: { src: [‘<%= config.src %>/1.html‘], true, replacements: [{ from‘var requestAddress = "";‘, to‘var requestAddress = "http://blog.csdn.net/ligang2585116";‘ }] }}
Example : Adding a MD5 stamp to 1.js and replacing a 1.html reference to a 1.js
//Grunt-filerev file plus MD5 summary//Grunt-filerev-replace Replace file references by Grunt-filerevAdd task in//Grunt.initconfig ({})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 '}}//Registration TasksGrunt.registerinittask ("JS-MD5","Add md5 for JS", [' Filerev:js ',' Filerev_replace:js ']);
Grunt common plug-ins and sample descriptions