要提前安装
npm install grunt-contrib-watch -g
npm install grunt-contrib-connect -g
npm install connect-livereload -g
| module.exports = function(grunt) { | |
| grunt.initConfig({ | |
| // https://github.com/gruntjs/grunt-contrib-watch | |
| // grunt.loadNpmTasks('grunt-contrib-watch'); | |
| // 页面上插入 <script src="http://localhost:35729/livereload.js"></script> | |
| watch: { | |
| scripts: { | |
| files: ['**/*'], | |
| task: [], | |
| options: { | |
| livereload: true | |
| } | |
| } | |
| } | |
| // https://github.com/gruntjs/grunt-contrib-connect | |
| // grunt.loadNpmTasks('grunt-contrib-connect'); | |
| // 通过 connect-livereload 插入 livereload 脚本 | |
| connect: { | |
| server: { | |
| options: { | |
| port: 8000, | |
| base: '_site', | |
| middleware: function(connect, options) { | |
| return [ | |
| require('connect-livereload')(), | |
| connect.static(options.base), | |
| connect.directory(options.base) | |
| ]; | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| }; | |