原文地址:

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的更多相关文章

  1. grunt任务之seajs模块打包

    grunt与seajs grunt是前端流行的自定义任务的脚手架工具,我们可以使用grunt来为我们做一些重复度很高的事情,如压缩,合并,js语法检查等.通过定义grunt的配置文件Gruntfile ...

  2. (绝对官方好用,快速上手)针对grunt之前写的那篇有些乱,这次总结个清晰的

    安装 Grunt基于Node.js,安装之前要先安装Node.js,然后运行下面的命令. sudo npm install grunt-cli -g grunt-cli表示安装的是grunt的命令行界 ...

  3. Grunt :任务自动管理工具

    来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 在Javascript的开发过程中,经常会遇到一些重复性的任务,比如合并文件.压缩代码.检查语法错误.将Sass代码 ...

  4. 转:Grunt:任务自动管理工具

    Grunt:任务自动管理工具 来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 目录 安装 命令脚本文件Gruntfile.js Gruntfile.js实例:gru ...

  5. Grunt打包之seajs项目【转】

    原文:http://www.cnblogs.com/accordion/p/4508154.html grunt与seajs grunt是前端流行的自定义任务的脚手架工具,我们可以使用grunt来为我 ...

  6. 前端工程化系列[04]-Grunt构建工具的使用进阶

    在前端工程化系列[02]-Grunt构建工具的基本使用和前端工程化系列[03]-Grunt构建工具的运转机制这两篇文章中,我们对Grunt以及Grunt插件的使用已经有了初步的认识,并探讨了Grunt ...

  7. Grunt:任务自动管理工具(收藏+转载)

    原文:http://javascript.ruanyifeng.com/tool/grunt.html 安装 命令脚本文件Gruntfile.js Gruntfile.js实例:grunt-contr ...

  8. grunt简记

    grunt和gulp都是前端自动化的工具,grunt更成熟,插件社区全.大:gulp比较年轻,性能更好,更简单容易.具体使用哪种可根据实际项目组来决定. 创建任务 grunt默认执行的是default ...

  9. 现代JavaScript开发者的工具箱

    自从HTML5变得流行以来,整个Web平台取得了长足的进步,人们也开始将JavaScript视为一门能够创建复杂应用的语言.许多新的API纷纷浮现,而关于浏览器如何应用这些技术的文章也大量涌现. 作为 ...

随机推荐

  1. linux下系统启动时,几个配置文件 /etc/profile、~/.bash_profile 等几个文件的执行过程,先后顺序

    1. 在登录Linux时要执行文件的过程如下: 在刚登录Linux时, 首先启动 /etc/profile 文件, 然后再启动用户目录下的 ~/.bash_profile. ~/.bash_login ...

  2. mysql关于列转行的想法,以及列求乘集

    mysql列转行可以通过concat,先分组然后连接. show VARIABLES like '%group%' select @@group_concat_max_len SELECT GROUP ...

  3. Java读写大文本文件(2GB以上)

    如下的程序,将一个行数为fileLines的文本文件平均分为splitNum个小文本文件,其中换行符'r'是linux上的,windows的java换行符是'\r\n': package kddcup ...

  4. 【PHP】linux搭建PHP运行环境

    之前在windows下写了hello world,终归是不够用啊,因为开发环境是Linux,怎么办呢~~~学习学习再学习 写在前面的话:我从百度文库的一个文章里摘出来的,原文章名称<Linux下 ...

  5. 【Linux】Mutex互斥量线程同步的例子

    0.互斥量  Windows下的互斥量 是个内核对象,每次WaitForSingleObject和ReleaseMutex时都会检查当前线程ID和占有互斥量的线程ID是否一致. 当多次Wait**时就 ...

  6. jQuery对select标签的常用操作

    1.获取当前选中项的value. $("#selector").val(); 2.获取当前选中项的text. $("#selector").find(" ...

  7. 庞锋 OpenCV 视频 学习进度备忘

    书签:另外跳过的内容有待跟进 学习资源: opencv视频教程目录(初级)   主讲:庞锋,毕业于电子科技大学 知识基础支持: 线性代数 应用数学 跳过的内容: 1.第1~6集跳过,简单.(2014- ...

  8. nagios为监控图像添加图片

    1. 背景介绍 在监控web页面上显示主机都为问号,如下图所示: 本文的主要目的就是将监控的图片添加进去,让监控图像变得美观. 2. 图片的下载地址 图片的下载地址如下: https://exchan ...

  9. 高效使用STL

    高效使用STL  参考:http://blog.jobbole.com/99115/ 仅仅是个选择的问题,都是STL,可能写出来的效率相差几倍:熟悉以下条款,高效的使用STL: 当对象很大时,建立指针 ...

  10. Windows8.1 安装office2013并激活

    之前笔记本上安装的东西太多了,启动比较慢,打算重做系统,正好同事有一个Windows8.1的系统盘,直接做了一个Windows8.1的系统.界面清爽,速度还可以,系统安装完成以后,准备安装office ...