周末在家看angularJS, 用grunt的livereload的自动刷新, 搞了大半天, 现在把配置贴出来, 免得以后忘记了, 只要按照配置一步步弄是没有问题的;

  开始的准备的环境安装是:

  (1):nodeJS,去官方网站下载(href);

  (2):然后把nodeJS加到全局的环境变量里面去(nodeJS安装好了就能用npm这个命令了),参考(href);

  (3):执行npm install grunt -g 和 npm install -g grunt-cli,一个是安装服务端的gurnt一个是客户端的grunt(反正都安装就好了),参考(href)

  

  第一步:新建一个叫做Gruntfile.js的js文件

module.exports = function (grunt) {
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
connect: {
options: {
port: 9000,
hostname: '127.0.0.1', //默认就是这个值,可配置为本机某个 IP,localhost 或域名
livereload: 35729 //声明给 watch 监听的端口
},
server: {
options: {
open: true, //自动打开网页 http://
base: [
              //当前的severHttp服务目录;
"html"
//主目录
]
}
}
},
watch : {
options: {
livereload: 35729 // this port must be same with the connect livereload port
},
scripts: {
options: {
livereload: true
},
          //所有文件发生改变都执行自动reload
files : ['**/*']
}
}
});
grunt.registerTask('default',["connect","watch"]);
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
};

  

  2:新建一个package.json的文件, 直接在cmd(命令行)下执行npm install即可把所有的node_module自动下载下来;

{
"name": "nono",
"version": "0.0.0",
"description": "for watch",
"main": "Gruntfile.js",
"dependencies": {
"grunt": "~0.4.5",
"express": "~3.15.2",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-watch": "~0.5.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "sqqihao.github.com"
},
"keywords": [
"nono"
],
"author": "nono",
"license": "__MIT__"
}

  

  好了, 现在在当前目录下执行grunt, grunt会自动监控所有文件的变化, 当你的文件一旦发生改变的,  你通过127.0.0.1打开的所有html格式文件都会自动刷新;

;

grunt使用watch和livereload的Gruntfile.js的配置的更多相关文章

  1. Gruntfile.js文件配置项

    GRUNT安装与配置 Posted on 2016-08-19 18:13 听风吹来的种子 阅读(47) 评论(0) 编辑 收藏 安装 CLI npm install -g grunt-cli//全局 ...

  2. Grunt 自动化部署之css、image、javascript、html压缩Gruntfile.js配置

    grunt.initConfig方法 用于模块配置,它接受一个对象作为参数.该对象的成员与使用的同名模块一一对应. 每个目标的具体设置,需要参考该模板的文档.就cssmin来讲,minify目标的参数 ...

  3. ☀【Grunt】package.json, Gruntfile.js, npm install, grunt

    npm install --registry http://registry.npm.taobao.org/ 切换源 Grunt.js 在前端项目中的实战http://beiyuu.com/grunt ...

  4. Grunt:GruntFile.js

    ylbtech-Grunt:GruntFile.js 1.返回顶部 1. module.exports = function (grunt) { grunt.initConfig({ useminPr ...

  5. Grunt 之 watch 和 livereload

    现在 watch 中已经集成了 livereload ,所以把它们放在一起说明. watch 可以监控特定的文件,在添加文件.修改文件.或者删除文件的时候自动执行自定义的任务,比如 livereloa ...

  6. Gruntfile.js模板

    module.exports = function(grunt) { // 配置项 var AppConfig = { name: 'app', //源文件目录 src: 'app/src', //生 ...

  7. grunt自定义任务——合并压缩css和js

    npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...

  8. 使用grunt完成requirejs的合并压缩和js文件的版本控制

    最近有一个项目使用了 requirejs 来解决前端的模块化,但是随着页面和模块的越来越多,我发现我快要hold不住这些可爱的js文件了,具体表现在每个页面都要设置一堆 requirejs 的配置( ...

  9. 编写可维护的 Gruntfile.js

    load-grunt-tasks 插件 首先介绍下 load-grunt-tasks 这个插件. 我们一般都会把所有用到的插件以及插件的配置写到 Gruntfile.js 里面,对于小项目来说这个文件 ...

随机推荐

  1. leetcode-Maximum Subarray

    https://leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (contai ...

  2. Flash Builder快捷键

    代码助手:Ctrl+Space(简体中文操作系统是Alt+/)快速修正:Ctrl+1单词补全:Alt+/打开外部Java文档:Shift+F2 显示搜索对话框:Ctrl+H快速Outline:Ctrl ...

  3. centos下pip安装mysql_python

    今天在使用pip安装mysql_python时,遇到一些问题,现记录下来. 1.执行pip install mysql-python时,报错 Running setup.py egg_info for ...

  4. C#综合揭秘——细说多线程(下)

    引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个方面介绍多线程的开发.其中委托的BeginInvoke方法以及回调函数最为常用.而 I/O线程可能 ...

  5. 一。常用UIView的属性和方法

    1.frame 控件所在的矩形框的位置和尺寸(以父控件的左上角为坐标原点) 2.bounds 控件 控件所在的矩形框的位置和尺寸(以自己的左上角为坐标原点,所以bounds的x/y一般为0) 3.ce ...

  6. 十一、常用的NSArray和NSMutableArray方法

    1.概念 用来存储OBJ对象的有序列表,它是不可变的 2.创建常用方法 + (id)array + (id)arrayWithObect:(id)anObject + (id)arrayWithObe ...

  7. C语言 百炼成钢11

    //题目31:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 //判断第二个字母. #define _CRT_SECURE_NO_WARNINGS #include<st ...

  8. U3D临时文件GICache巨大

    C:\Users\asus\AppData\LocalLow\Unity\Caches\GiCache 看名字似乎是全局光的缓存,可以通过Edit - Preference - GI Cache,选中 ...

  9. Got a packet bigger than 'max_allowed_packet' bytes

    昨天用导入数据的时候发现有的地方有这个错误.后来才发现我用RPM包装的MYSQL配置文件里面有old_passwords=1去掉就可以了. Got a packet bigger than ‘max_ ...

  10. windows 7 和 Ubuntu的双系统安全删除Ubuntu

    1,准备文件 百度云盘链接:http://pan.baidu.com/s/1kVxuwSn 密码:e8ma 2,操作流程 #1,进入win7,将第一步下载的文件放在C:\windows\system3 ...