From cd3653c1e28e10257e8740b59b4fcef74d0f0b26 Mon Sep 17 00:00:00 2001 From: Scott Bessler Date: Thu, 1 Aug 2013 22:00:41 -0700 Subject: [PATCH] Augment and cleanup grunt/node configuration. * .gitignore node_modules * fix missing jshint dependency in packages.json * add grunt-contrib-connect and grunt-contrib-livereload * configure ```grunt server``` command that starts a local dev server with livereload functionality. this watches for file changes and will reload the browser page as it detects them. --- .gitignore | 2 ++ Gruntfile.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 6 +++++- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000..a56a7ef437dc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules + diff --git a/Gruntfile.js b/Gruntfile.js index 4e05a3067bc2d..43bc3bfa669c2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,17 @@ 'use strict'; +var LIVERELOAD_PORT = 35729; +var lrSnippet = require('connect-livereload')({ + port: LIVERELOAD_PORT +}); +var mountFolder = function(connect, dir) { + return connect.static(require('path').resolve(dir)); +}; + module.exports = function (grunt) { var post = ['src/client.js','src/post.js']; + var webapp = './'; // Project configuration. grunt.initConfig({ @@ -58,16 +67,54 @@ module.exports = function (grunt) { "common/css/bootstrap.light.min.css": "vendor/bootstrap/less/bootstrap.light.less" } } + }, + connect: { + options: { + port: 9000, + // Change this to '0.0.0.0' to access the server from outside. + // hostname: '0.0.0.0' + }, + livereload: { + options: { + middleware: function(connect) { + return [ + lrSnippet, + mountFolder(connect, webapp), + ]; + } + } + }, + }, + watch: { + options: { + livereload: LIVERELOAD_PORT, + nospawn: true, + }, + reloadassets: { + files: [ + webapp + '*.html', + webapp + 'partials/*.html', + webapp + 'panels/**/*.{html,js}', + webapp + 'js/*.js', + webapp + 'common/**/*.{html,css,js,png,gif}', + ] + }, } }); // load plugins grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('assemble-less'); - + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-connect'); // Default task. grunt.registerTask('default', ['jshint','less']); - + grunt.registerTask('server', function() { + grunt.task.run([ + 'connect:livereload', + 'watch' + ]); + }); }; diff --git a/package.json b/package.json index 12ab167e1d3d2..27e5de40235e9 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,11 @@ "grunt": "~0.4.0", "grunt-contrib": "~0.7.0", "grunt-contrib-jshint": "~0.6.0", - "assemble-less": "~0.4.8" + "assemble-less": "~0.4.8", + "grunt-contrib-connect": "~0.3.0", + "connect-livereload": "~0.2.0", + "grunt-contrib-watch": "~0.5.1", + "jshint": "~2.1.8" }, "license": "Apache License" }