下述给出了经常使用Grunt插件,并列举了部分插件演示样例:

插件名称 说明 Github地址
grunt-contrib-clean 清空文件和目录 https://github.com/gruntjs/grunt-contrib-clean
grunt-contrib-copy 拷贝文件和目录 https://github.com/gruntjs/grunt-contrib-copy
grunt-contrib-concat 连接、合并文件 https://github.com/gruntjs/grunt-contrib-concat
grunt-svgstore (svg)从指定目录合并svg https://github.com/FWeinb/grunt-svgstore
grunt-csscomb (CSS)格式化 https://github.com/csscomb/grunt-csscomb
grunt-contrib-less (CSS)将Less编译成css https://github.com/gruntjs/grunt-contrib-less
grunt-contrib-cssmin (CSS文件)压缩 https://github.com/gruntjs/grunt-contrib-cssmin
grunt-contrib-uglify (JS文件)压缩 https://github.com/gruntjs/grunt-contrib-uglify
grunt-contrib-htmlmin (HTML文件)压缩 https://github.com/gruntjs/grunt-contrib-htmlmin
grunt-filerev 文件内容hash(MD5) https://github.com/yeoman/grunt-filerev
grunt-filerev-replace 替换通过grunt-filerev的文件引用 https://github.com/solidusjs/grunt-filerev-replace
grunt-text-replace (文本文件)使用字符串、正则、函数替换内容 https://github.com/yoniholmes/grunt-text-replace
grunt-html-build (HTML文件)添加js、css、模板引用。移除调试代码 https://github.com/spatools/grunt-html-build
grunt-autoprefixer 加入前缀依赖Can I Use数据库 https://github.com/nDmitry/grunt-autoprefixer
grunt-parallel 并行执行命令和任务 https://github.com/iammerrick/grunt-parallel
grunt-contrib-watch 文件发生改变执行任务 https://github.com/gruntjs/grunt-contrib-watch
load-grunt-tasks 使用通配符载入全部任务 https://github.com/sindresorhus/load-grunt-tasks
time-grunt 显示执行任务的执行时间 https://github.com/sindresorhus/time-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.html文件里的var requestAddress = "";替换为var requestAddress = "http://blog.csdn.net/ligang2585116";

// grunt-text-replace 使用字符串、正则、函数替换文本内容
// grunt.initConfig({})中添加Task
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.html1.js引用

// grunt-filerev 文件加MD5摘要
// grunt-filerev-replace 替换通过grunt-filerev的文件引用
// grunt.initConfig({})中添加Task
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']);

Grunt经常使用插件及演示样例说明的更多相关文章

  1. AppCan移动应用开发平台新增9个超有用插件(内含演示样例代码)

    使用AppCan平台进行移动开发.你所须要具备的是Html5+CSS +JS前端语言基础.此外.Hybrid混合模式应用还需结合原生语言对功能模块进行封装,对于没有原生基础的开发人员,怎样实现App里 ...

  2. 图标插件--jqplot实现柱状图及饼图,表盘图演示样例

    柱状图 在jqPlot图表插件使用说明(一)中,我们已经能够通过jqPlot绘制出比較简单的线形图.通过查看源码.我们也能够看出,线形图是jqPlot默认的图表类型: /** * Class: Ser ...

  3. 构造Scala开发环境并创建ApiDemos演示样例项目

    从2011年開始写Android ApiDemos 以来.Android的版本号也更新了非常多,眼下的版本号已经是4.04. ApiDemos中的样例也添加了不少,有必要更新Android ApiDe ...

  4. [hadoop系列]Pig的安装和简单演示样例

    inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish ).(来源:http://blog.csdn.net/inkfish) Pig是Yaho ...

  5. Broccoli &amp; Babel使用演示样例

    1 创建项目project文件夹:test 2 在test下运行 npm init 按提示填写package.json文件 3 安装broccoli命令行工具broccoli-cli npm inst ...

  6. 使用Dropzone上传图片及回显演示样例

    一.图片上传所涉及到的问题 1.HTML页面中引入这么一段代码 <div class="row"> <div class="col-md-12" ...

  7. Android网络(3):HttpClient作client,Tomcat Servlet作server的交互演示样例

    前面相继介绍了Android网络编程里的Socket传输图片.HttpURLConnection,今天看HttpClient. 第一部分:JavaEE版的Eclipse配置Tomcat [备注:开发后 ...

  8. JDBC连接MySQL数据库及演示样例

    JDBC是Sun公司制定的一个能够用Java语言连接数据库的技术. 一.JDBC基础知识         JDBC(Java Data Base Connectivity,java数据库连接)是一种用 ...

  9. java 覆盖hashCode()深入探讨 代码演示样例

    java 翻盖hashCode()深入探讨 代码演示样例 package org.rui.collection2.hashcode; /** * 覆盖hashcode * 设计HashCode时最重要 ...

随机推荐

  1. Eclipse SQLExplorer插件的安装和使用

    from: http://blog.csdn.net/flashlm/archive/2007/06/30/1672836.aspx 插件名称: SQLExplorer 插件分类: SQL Edito ...

  2. 【转】Kotlin 和 Checked Exception

    Kotlin 和 Checked Exception 最近 JetBrains 的 Kotlin 语言忽然成了热门话题.国内小编们传言说,Kotlin 取代了 Java,成为了 Android 的“钦 ...

  3. Struts2之数据标签(二)

    Struts2之数据标签(一):http://blog.csdn.net/u012561176/article/details/46848817 1.action标签:使用此标签能够同意在JSP页面中 ...

  4. nginx+php-fpm性能参数优化原则

    1.worker_processes 越大越好(一定数量后性能增加不明显)   2.worker_cpu_affinity 所有cpu平分worker_processes 要比每个worker_pro ...

  5. Mysql:MyIsam和InnoDB的区别

    MyISAM: 这个是默认类型,它是基于传统的ISAM类型,ISAM是Indexed Sequential Access Method (有索引的 顺序访问方法) 的缩写,它是存储记录和文件的标准方法 ...

  6. Android Studio 环境搭建参考,jdk10javac命令提示不是内部或外部命令

    https://blog.csdn.net/qq_33658730/article/details/78547789 win10下Android Studio和SDK下载.安装和环境变量配置 http ...

  7. 搭建MVC及WEB API项目框架时碰到的问题集合

    前言 刚开始创建MVC与Web API的混合项目时,碰到好多问题,今天拿出来跟大家一起分享下.有朋友私信我问项目的分层及文件夹结构在我的第一篇博客中没说清楚,那么接下来我就准备从这些文件怎么分文件夹说 ...

  8. Android 架构师技能图谱(转载)

    架构与设计 设计模式 重构 技术选型 特性 可用性 性能 包大小 方法数 文档 技术支持 UI架构模式 MVC MVP MVVM 研发工具 集成开发环境 Android Studio Sublime ...

  9. ios block一定会犯的几个错误

    贴几段斯坦福大学关于gcd的代码,这段代码逐步演示了如何修正错误,其中用到的既是串行队列   1.这个是原始代码 - (void)viewWillAppear:(BOOL)animated { NSD ...

  10. [svc]NFS存储企业场景及nfs最佳实战探究

    办公网络里人一般系统用共享,尤其是财务, 他们喜欢直接点开编辑. 而不喜欢ftp nfs在网站架构中的用途 注: 如果pv量少,则放在一台机器上速度更快,如果几千万pv,则存储分布式部署. 网站架构中 ...