如何设置Grunt
原文地址:
Step 1: Install Node.js
Download a Node installer and run it. Installation packages are available for Mac, Windows, Linux, and SunOS. Alternatively, you can compile and install it from source.
Step 2: Install Grunt
Install Grunt using the Node package manager: (安装在Global)
$ npm install -g grunt
$ npm install -g grunt-cli
Providing -g installs the package globally.
Providing -g installs the package globally.
Step 3: Create a Gruntfile.js
Now create a file called Gruntfile.js in your project directory.
Then copy and paste in the example configuration shown just below this paragraph. You'll just need to change the (commented) lines that define which files Grunt should keep an eye on, as well as the source and destination paths to the LESS and CSS files.
Example:
module.exports = function(grunt) {
grunt.initConfig({
less: {
development: {
options: {
compress: true,
yuicompress: true,
optimization: 2
},
files: {
// target.css file: source.less file
"css/main.css": "less/main.less"
}
}
},
watch: {
styles: {
files: ['less/**/*.less'], // which files to watch
tasks: ['less'],
options: {
nospawn: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
};
Note that supplying /**/ in the watch path will watch files recursively under that directory.
Step 4: Configure the package file
If you do not have an existing package.json file in your project directory, create one:(创建Config file)
$ cd YOUR_PROJECT_DIRECTORY
$ npm init
When you have a valid package.json file, open it and add the following development dependencies: (设置需要哪些Dependencies)
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-less": "~0.11.0",
"grunt-contrib-watch": "~0.6.1"
},
Then install the package dependencies:(在打Grunt的时候安装Dependencies)
$ npm install
Step 5: Start Grunt
$ grunt
While Grunt is running, it will compile your stylesheets every time you
讨论,按照如上设置后会出现一个node_modules文件夹,里面有grunt, grunt-contrib-less, grunt-contrib-watch,由于其文件path太长,导致VS deploy的时候出错,并且会在Recycle bin里创建几千个offline.html, 建议每次deploy的时候手动把node_modules移出project。
如何设置Grunt的更多相关文章
- grunt任务之seajs模块打包
grunt与seajs grunt是前端流行的自定义任务的脚手架工具,我们可以使用grunt来为我们做一些重复度很高的事情,如压缩,合并,js语法检查等.通过定义grunt的配置文件Gruntfile ...
- (绝对官方好用,快速上手)针对grunt之前写的那篇有些乱,这次总结个清晰的
安装 Grunt基于Node.js,安装之前要先安装Node.js,然后运行下面的命令. sudo npm install grunt-cli -g grunt-cli表示安装的是grunt的命令行界 ...
- Grunt :任务自动管理工具
来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 在Javascript的开发过程中,经常会遇到一些重复性的任务,比如合并文件.压缩代码.检查语法错误.将Sass代码 ...
- 转:Grunt:任务自动管理工具
Grunt:任务自动管理工具 来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 目录 安装 命令脚本文件Gruntfile.js Gruntfile.js实例:gru ...
- Grunt打包之seajs项目【转】
原文:http://www.cnblogs.com/accordion/p/4508154.html grunt与seajs grunt是前端流行的自定义任务的脚手架工具,我们可以使用grunt来为我 ...
- 前端工程化系列[04]-Grunt构建工具的使用进阶
在前端工程化系列[02]-Grunt构建工具的基本使用和前端工程化系列[03]-Grunt构建工具的运转机制这两篇文章中,我们对Grunt以及Grunt插件的使用已经有了初步的认识,并探讨了Grunt ...
- Grunt:任务自动管理工具(收藏+转载)
原文:http://javascript.ruanyifeng.com/tool/grunt.html 安装 命令脚本文件Gruntfile.js Gruntfile.js实例:grunt-contr ...
- grunt简记
grunt和gulp都是前端自动化的工具,grunt更成熟,插件社区全.大:gulp比较年轻,性能更好,更简单容易.具体使用哪种可根据实际项目组来决定. 创建任务 grunt默认执行的是default ...
- 现代JavaScript开发者的工具箱
自从HTML5变得流行以来,整个Web平台取得了长足的进步,人们也开始将JavaScript视为一门能够创建复杂应用的语言.许多新的API纷纷浮现,而关于浏览器如何应用这些技术的文章也大量涌现. 作为 ...
随机推荐
- 【英语】Bingo口语笔记(8) - 爆破音的发音技巧
轻读,有时候甚至是听不到的,就嘴巴碰一下而已.
- 【转】bzero, memset ,setmem 区别
原文网址:http://blog.csdn.net/agathe/article/details/6066157 bzero 原型: extern void bzero(void *s, int n ...
- javascript对象之 selectionStart selectionEnd
<script> function inserttag(){ var text=document.getElementById('con'); text.focus(); var star ...
- JavaScript/jQuery 表单美化插件小结
Niceforms Niceforms是一款独立的表单美化工具,当前版本为2.0 官方主页:http://www.emblematiq.com/lab/niceforms/ 官方演示:http://w ...
- Loadrunner 性能指标定位系统瓶颈
判断CPU瓶颈 1, %processor time 平均值大于95 2, processor queue length大于2 (大于处理器个数+1).可以确定CPU瓶颈 3, CPU空闲时间为零(z ...
- 细雨学习笔记:Jmeter集合点
设置集合点的原则 (1) 集合点设置数<=线程组线程数量(因为大于线程组线程数量的话就永远也到不了集合点) (2)线程组线程数量是集合点设置数的整数倍(因为分组有余数的话最后一组永远也到不了集合 ...
- Oracle VirtualBox 模拟Android系统 素材
Android to x86 下载地址: http://www.android-x86.org/download VirtualBox 下载地址: https://www.virtualbox.org ...
- map使用.xml
map 是一种关联容器, 提供一对一的关联, 关联的形式为: KEY----VALUE 关键字不重复.multimap与map类似,但是允许关键字重复 即:关键字和与之对 ...
- linux笔记_20150417_ubuntu 常见问题_文件_音乐播放器
最近在学习ubuntu的过程中,遇到了一些问题,就记下来了它的解决办法.以希望对你也有用. ),至少保证周围局域网内用户可以访问.至于配置文件,内容比较少,反正对我来讲能用就ok了~不知道会不会很弱 ...
- 精选PSD素材下载周刊【Goodfav PSD 20130720】
我们每周精选来自Goodfav PSD的免费PSD素材,有兴趣的朋友尤其是做设计工作的,不妨收藏或者下载. 这些现成的PSD素材能给我们一些相关的灵感,从而提高工作的效率. 1.File Upload ...