Skip to content

Commit

Permalink
updated to use grunt-express v0.2.0, added example to use grunt-regar…
Browse files Browse the repository at this point in the history
…de, grunt-contrib-livereload. Show case multiple ways to trigger a server restart, as well as browser live reload
  • Loading branch information
blai committed Mar 1, 2013
1 parent 0bfd5c9 commit a13a0cf
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
/node_modules/
.idea
Empty file added .server
Empty file.
32 changes: 16 additions & 16 deletions Gruntfile.js
Expand Up @@ -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'
Expand All @@ -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: {
Expand All @@ -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']);

Expand Down
8 changes: 7 additions & 1 deletion README.md
@@ -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

Expand All @@ -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)_

Expand Down
7 changes: 5 additions & 2 deletions app/server.js
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -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"
}
}
Binary file added public/favicon.ico
Binary file not shown.
Empty file added public/files/a.txt
Empty file.
3 changes: 3 additions & 0 deletions public/index.html
Expand Up @@ -9,4 +9,7 @@
});
</script>
</head>
<body>
hello!
</body>
</html>

0 comments on commit a13a0cf

Please sign in to comment.