使用node-livereload自动刷新页面
1. 安装node
2. 安装python
3. 安装connect, serve-static和node-livereload (以下都假设命令行当前目录为e:\WebSite)
e:\WebSite>npm install connect
e:\WebSite>npm install serve-static
e:\WebSite>npm install livereload
如果出现类似:MSB8036: The Windows SDK version 8.1 was not found的错误,请使用Visual Studio安装包安装"Tools and Windows SDKs"
4. 安装Google Chrom 插件 LiveReload
https://chrome.google.com/webstore/detail/jnihajbhpnppcggbcgedagnkighmdlei
5. 创建Web Server和File watch server, 脚本如下保存为e:\WebSite\server.js
var connect = require('connect'); var serveStatic = require('serve-static'); var app = connect(); app.use(serveStatic(__dirname + "\\WebSite")); app.listen(5000); console.log('Web Server start') livereload = require('livereload'); server = livereload.createServer(); server.watch(__dirname + "\\WebSite"); console.log('File watching start')
6. 运行server.js
e:\WebSite>node server.js
这样只要e:\WebSite下的文件一更新,浏览器打开的页面就会自动刷新