周末在家看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. Helloworld -SilverN

    /*Hello World*/ #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  2. runc create container 流程分析

    1.// runc/create.go Action: func(context *cli.Context) error 首先调用spec, err := setupSpec(context)加载配置 ...

  3. 边工作边刷题:70天一遍leetcode: day 85-1

    Inorder Successor in BST 要点:这题要注意的是如果不是BST,没法从树结构上从root向那边找p,只能遍历.而根据BST,可以只走正确方向 如果不检查right子树,可以从ro ...

  4. JavaWeb学习之Servlet(四)----ServletConfig获取配置信息、ServletContext的应用

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140877.html [正文] 一.ServletConfig:代表当前 ...

  5. np问题

    NP(np) Time Limit:1000ms Memory Limit:64MB 题目描述 LYK 喜欢研究一些比较困难的问题,比如 np 问题.这次它又遇到一个棘手的 np 问题.问题是这个样子 ...

  6. Android安全机制(2) Android Permission权限控制机制

    http://blog.csdn.net/vshuang/article/details/44001661 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 1.概述 Andro ...

  7. Android Studio使用中的异常

    Android studio教程:[4]真机测试 1.连不上手机 Android Studio识别不了手机(最后还是恢复成勾中的状态),重启,Android Studio连接真机没反应? 2.连上手机 ...

  8. [C#]動態叫用Web Service

    http://www.dotblogs.com.tw/jimmyyu/archive/2009/04/22/8139.aspx 摘要 Web Service對大家來說想必都不陌生,也大都了解Web S ...

  9. 1从零开始学习Xamarin.iOS安装篇

    安装和配置xamarin.ios 最近.net 开源新闻很火呀,于是想学习xamarin,早1年前就了解过这个东西,但是一直没有时间来学习,我这里装的是MAC上面的版本,废话不多说开始第一步安装. 概 ...

  10. 又折腾到这么晚 , 图片Viewpager PagerIndicator,listview 和侧边栏滑动的事件处理

    代码 思路 根据坐标判断 事件是否拦截 调用 getParent().requestDisallowInterceptTouchEvent(true);方法告诉上层ViewGroup 是否拦截 返回t ...