日期:2014-05-16 浏览次数:20620 次
{ "name": "live-reload-test", "version": "0.0.0", "dependencies": { "grunt": "*", "grunt-contrib-connect": "*", "grunt-contrib-watch": "*", "connect-livereload": "*" } }
module.exports = function (grunt) { var LIVERELOAD_PORT = 35729; // lrSnippet is just a function. // It's a piece of Connect middleware that injects // a script into the static served html. var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT }); // All the middleware necessary to serve static files. var livereloadMiddleware = function (connect, options) { return [ // Inject a livereloading script into static files. lrSnippet, // Serve static files. connect.static(options.base), // Make empty directories browsable. connect.directory(options.base) ]; }; grunt.initConfig({ connect: { client: { options: { port: 9001, hostname: '0.0.0.0', base: 'src/', middleware: livereloadMiddleware } } }, watch: { client: { files: ['src/**/*'], tasks: [], options: { livereload: true } } } }); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('preview', ['connect:client', 'watch:client']); };