Permalink
Browse files

updated to use grunt-express v0.2.0, added example to use grunt-regar…

…de, grunt-contrib-livereload. Show case multiple ways to trigger a server restart, as well as browser live reload
  • Loading branch information...
1 parent 0bfd5c9 commit a13a0cf7ff6f9f1be38cb8fd39e51bc9ef8bacf7 @blai committed Mar 1, 2013
Showing with 36 additions and 22 deletions.
  1. +1 −0 .gitignore
  2. 0 .server
  3. +16 −16 Gruntfile.js
  4. +7 −1 README.md
  5. +5 −2 app/server.js
  6. +4 −3 package.json
  7. BIN public/favicon.ico
  8. 0 public/files/a.txt
  9. +3 −0 public/index.html
View
@@ -1 +1,2 @@
/node_modules/
+.idea
View
No changes.
View
@@ -12,12 +12,13 @@ module.exports = function(grunt) {
options: {
port: 9000,
bases: path.resolve('public'),
- keepalive: true,
- supervisor: true,
+ monitor: {},
+ debug: true,
server: path.resolve('./app/server')
}
}
},
+
jshint: {
options: {
jshintrc: '.jshintrc'
@@ -32,20 +33,18 @@ module.exports = function(grunt) {
src: ['test/**/*.js']
},
},
- watch: {
- gruntfile: {
- files: '<%= jshint.gruntfile.src %>',
- tasks: ['jshint:gruntfile']
+
+ regarde: {
+ pub: {
+ files: 'public/**/*',
+ tasks: ['livereload']
},
- // lib: {
- // files: '<%= jshint.lib.src %>',
- // tasks: ['jshint:lib', 'nodeunit']
- // },
- // test: {
- // files: '<%= jshint.test.src %>',
- // tasks: ['jshint:test', 'nodeunit']
- // },
+ trigger: {
+ files: '.server', // touch this file to restart the express server, just an example
+ tasks: 'express-restart:livereload'
+ }
},
+
jsbeautifier: {
files: ['Gruntfile.js'],
options: {
@@ -70,12 +69,13 @@ module.exports = function(grunt) {
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
- grunt.loadNpmTasks('grunt-contrib-watch');
+ grunt.loadNpmTasks('grunt-contrib-livereload');
grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks('grunt-express');
+ grunt.loadNpmTasks('grunt-regarde');
grunt.registerTask('format', ['jshint', 'jsbeautifier']);
- grunt.registerTask('server', ['express', 'watch']);
+ grunt.registerTask('server', ['livereload-start', 'express', 'regarde']);
// Default task.
grunt.registerTask('default', ['format', 'server']);
View
@@ -1,6 +1,10 @@
# grunt-express-example
-An example for how to use socket.io and express using [grunt-express](https://github.com/blai/grunt-express)
+An example for how to use socket.io and express using [grunt-express](https://github.com/blai/grunt-express). The example will:
+
+* reload the browser (when opened) using [grunt-contrib-livereload](https://github.com/gruntjs/grunt-contrib-livereload) and [grunt-regarde](https://github.com/yeoman/grunt-regarde)
+* restart the server using the built-in feature of `grunt-express`, and it will do so when any of the server script is changed, or when you 'touch' the `.server` file in project root (using a `grunt-regarde` watcher setup, see `Gruntfile.js`)
+
## Getting Started
@@ -17,6 +21,8 @@ app.get('/hello', function(req, res){
});
```
+To observe the browser refresh, change anything in the `<body>` tag of `public/index.html`, save the change and you should see browser automatically re-fresh.
+
## Documentation
_(Coming soon)_
View
@@ -12,9 +12,12 @@ io.sockets.on('connection', function (socket) {
});
});
+// use livereload middleware
+app.use(require('grunt-contrib-livereload/lib/utils').livereloadSnippet);
+
app.get('/hello', function(req, res){
- res.send('hello!');
- // res.send('bonjour!');
+ // res.send('hello!');
+ res.send('bonjour!');
});
exports = module.exports = server;
View
@@ -30,17 +30,18 @@
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "~0.1.2",
- "grunt-contrib-watch": "~0.2.0",
"grunt": "~0.4.0",
"grunt-jsbeautifier": "~0.1.5",
- "grunt-express": "~0.1.1"
+ "grunt-express": "~0.2.0",
+ "grunt-regarde": "~0.1.1"
},
"keywords": [
"grunt-express",
"example"
],
"dependencies": {
"express": "~3.1.0",
- "socket.io": "~0.9.13"
+ "socket.io": "~0.9.13",
+ "grunt-contrib-livereload": "~0.1.2"
}
}
View
Binary file not shown.
View
No changes.
View
@@ -9,4 +9,7 @@
});
</script>
</head>
+<body>
+ hello!
+</body>
</html>

0 comments on commit a13a0cf

Please sign in to comment.