grunt-develop
Version:
Run a Node.js application for development, with support for auto-reload.
125 lines (88 loc) • 3.15 kB
Markdown
> Run a Node.js application for development, with support for auto-reload.
* Requires Grunt >= 0.4.1 && Node.js >= 0.10.0
* ~~Does not provide a file-watch, [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) is helpful here~~
* No need to modify/export your server or alter your applications code
* ~~Non-blocking (the task completes immediately and the application will un in the background);~~ Run as last task
* ~~Reloads cleanly the application when the task is called again,
allowing for auto-reload.~~
This project has a lot of active contributors and users. Please submit a test along with any changes made. Thanks!
```bash
$ npm install grunt-develop
```
```javascript
module.exports = function(grunt) {
grunt.initConfig({
develop: {
server: {
file: 'app.js',
nodeArgs: ['--debug'], // optional
args: ['appArg1', 'appArg2'] // optional
env: { NODE_ENV: 'development'} // optional
}
}
});
grunt.loadNpmTasks('grunt-develop');
grunt.registerTask('default', ['develop']);
};
```
You may also have develop automatically restart coffeescript based node
applications by using the `cmd` option. This option allows the user to
specify which command/executable to use when restarting the server.
```coffeescript
module.exports = (grunt) ->
grunt.initConfig
develop:
server:
file: 'app.coffee'
cmd: 'coffee'
grunt.loadNpmTasks 'grunt-develop'
grunt.registerTask 'default', ['develop']
```
To support auto-reload on changes, for example:
```javascript
module.exports = function(grunt) {
grunt.initConfig({
watch: {
js: {
files: [
'app.js',
'routes/**/*.js',
'lib/*.js'
],
tasks: ['develop'],
options: { nospawn: true }
}
},
develop: {
server: {
file: 'app.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-develop');
grunt.registerTask('default', ['develop']);
};
```
The [nospawn](https://github.com/gruntjs/grunt-contrib-watch/blob/master/README.md#optionsnospawn)
is required to keep the grunt context in which `grunt-develop` is running
your application.
Then you can run grunt as the following and get automatic restart of the application on file changes:
```bash
$ grunt
```
You may add any other task in the watch, like JS linting, asset compiling,
etc. and customize the watch to your needs. See
[](https://github.com/gruntjs/grunt-contrib-watch).
Copyright (c) 2013, Edward Hotchkiss.
[]: http://github.com/edwardhotchkiss/
[](https://bitdeli.com/free "Bitdeli Badge")