Grunt的使用
在Node环境下。需要预先安装好Node。
1、安装grunt-cli
[root@Luxh-01 ~]# npm install -g grunt-cli
2、创建一个目录test
[root@Luxh-01 ~]# mkdir test
3、进入test目录,创建一个package.json文件,内容如下:
{
"name": "grunt_test",
"description": "this is a demo",
"author": "Luxh"
}
4、安装grunt,只需安装到开发环境依赖中。
[root@Luxh-01 test]# npm install grunt --save-dev
安装完成,package.json文件如下:
{
"name": "grunt_test",
"description": "this is a demo",
"author": "Luxh",
"devDependencies": {
"grunt": "^0.4.5"
}
}
5、这里我要是有grunt完成:clean(清除文件)、copy(复制文件)、coffee(coffee编译成js)三个功能,所有我需要安装三个grunt插件:
[root@Luxh-01 test]# npm install grunt-contrib-clean --save-dev
[root@Luxh-01 test]# npm install grunt-contrib-copy --save-dev
[root@Luxh-01 test]# npm install grunt-contrib-coffee --save-dev
安装完成后:package.json文件如下:
{
"name": "grunt_test",
"description": "this is a demo",
"author": "Luxh",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-coffee": "^0.12.0",
"grunt-contrib-copy": "^0.7.0"
}
}
6、编写Grunt的配置文件:Gruntfile.js 内容如下:
module.exports = function(grunt) {
grunt.initConfig({
clean:{
main:{
src:'dest' //清除dest目录
}
},
copy: {
main: {
expand: true,
cwd: 'src/', //指定源文件目录
src: ['**','!**/*.coffee'], //不复制coffee文件
dest: 'dest/' //复制到dest目录下
}
},
coffee:{
main:{
expand:true,
cwd:'src',
src:['**/*.coffee'], //src目录下的coffee文件编译到dest目录
dest:'dest',
ext:'.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.registerTask('default', ['clean:main','copy:main','coffee:main']);
};
7、在test目录下创建src目录,在里面编写coffee。
8、执行grunt命令,将会依次执行 clean、copy、coffee,如果只需要执行clean,则允许 grunt copy
Grunt的使用的更多相关文章
- 初学seaJs模块化开发,利用grunt打包,减少http请求
原文地址:初学seaJs模块化开发,利用grunt打包,减少http请求 未压缩合并的演示地址:demo2 学习seaJs的模块化开发,适合对seajs基础有所了解的同学看,目录结构 js — —di ...
- grunt配置任务
这个指南解释了如何使用 Gruntfile 来为你的项目配置task.如果你还不知道 Gruntfile 是什么,请先阅读 快速入门 指南并看看这个Gruntfile 实例. Grunt配置 Grun ...
- 快速开发Grunt插件----压缩js模板
前言 Grunt是一款前端构建工具,帮助我们自动化搭建前端工程.它可以实现自动对js.css.html文件的合并.压缩等一些列操作.Grunt有很多插件,每一款插件实现某个功能,你可以通过npm命名去 ...
- 是时候搁置Grunt,耍一耍gulp了
也算是用了半年Grunt,几个月前也写过一篇它的入门文章(点此查看),不得不说它是前端项目的一个得力助手.不过技术工具跟语言一样日新月异,总会有更好用的新的东西把旧的拍死在沙滩上(当然Grunt肯定没 ...
- 应用Grunt自动化地优化你的项目前端
在不久前我曾写了一篇 应用r.js来优化你的前端 的文章,为大家介绍了r.js这个实用工具,它可以很好地压缩.合并前端文件并打包整个项目.但是如果将r.js放到项目中,我们不得不顾及到一个问题——项目 ...
- Grunt(页面静态引入的文件地址的改变探究)-V2.0
相关插件的引用: grunt-usemin 对页面的操作 grunt-contrib-cssmin 压缩css load-grunt-tasks 瘦身gruntfile grunt-rev给md5 ...
- Grunt基本使用-V1.0
浅语:grunt中文网:http://www.gruntjs.net/ 第一步:Grunt 依赖 Node.js 所以在安装之前确保你安装了 Node.js.然后开始安装 Grunt. 实际上,安装的 ...
- nodejs、npm、grunt——名词解释
最近着手开发一个新项目,打算从工程化的角度整理一套自己的前端开发.发布体系. grunt这些工具,之前别人用我也用,并没有认真想过它们的前世今生,正好趁着这个机会,我来理一理目前业界比较流行这些工具的 ...
- grunt自定义任务——合并压缩css和js
npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...
- Grunt学习使用
原文地址:Grunt学习使用必看 grunt简介神马的不多说,到处一大堆. 我只说说我已经实现了的代码. 按照官方的教程 相信已经配置好了,接下来说 package.json 和 Gruntfile. ...
随机推荐
- Decorator实现AOP编程。
Program.cs class Program { static void Main(string[] args) { User user = " }; var processor = T ...
- CLR via C# 3rd - 03 - Shared Assemblies and Strongly Named Assemblies
1. Weakly Named Assembly vs Strong Named Assembly Weakly named assemblies and strongly named ...
- 因特网服务的类型(协议),目前最流行的类型是 http协议
在学习超链接中,在HTML上点击QQ图标时会 自动的启动自己本地QQ客户端,其方法是使用了超链协议 一些常用协议如下: file资源是本地计算机上的文件.格式file:/// ftp通过 FTP访问资 ...
- equals()和hashCode()隐式调用时的约定
package com.hash; import java.util.HashMap; public class Apple { private String color; public Apple( ...
- HDU 1010 Tempter of the Bone(深度+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...
- Xcode8更新CocoaPods报错解决办法
Apple发布了iPhone7同时也发布了xcode8,第一时间升级,并且用Xcode8集成cocoapods但是打开工程,会报一大堆错误解决这个问题 由于OSX的安全解决方案,所以默认路径不能安装, ...
- CentOS上yum安装JDK
转: http://blog.csdn.net/onepiecehuiyu/article/details/17189571
- android Sqlite select * from myDatabase没有内容的问题
没什么好说的,但是却在初学的时候弄了很久,百度google查了很多资料.后来才发现,竟然是少了个分号结束符的原因. 开始怀疑人生了...
- jffs2文件系统制作
内核: linux-3.0 uboot: 2010.09 开发板: fl2440 交叉编译器: 2011. ...
- 【转载】Python 描述符简介
来源:Alex Starostin 链接:www.ibm.com/developerworks/cn/opensource/os-pythondescriptors/ 关于Python@修饰符的文章可 ...