I like being productive and always looking for tools to work efficiently. Now I am working on a React isomorphic project, auto-watch setup is different on server side(restart server when file changed) and client side(to build static file when changed). However the idea of isomorphic is shared same React component on both server and client sides. There are much enough tools for auto-watch: webpack, grunt, gulp, nodemon, etc, and auto-build: webpack, grunt, gulp, browserify etc.
Find the right tool to do the right task, playing with them 1 after 1, this is the git of this example, hope it is helpful.
//app.jsvar express = require('express')var app = express()
app.get('/', function (req, res) {res.send('Hello World!')})
app.listen(3000, function () {console.log('Example app listening on port 3000!')})
And auto-watch is not on yet.
$ node app.js
Example app listening on port 3000!
$ npm install **--save-dev nodemon $**
./node_modules/nodemon/bin/nodemon.js app.js
[nodemon] 1.11.0[nodemon] to restart at any time, enter `rs`[nodemon] watching: *.*[nodemon] starting `node app.js`
Example app listening on port 3000!
Nodemon supports local and global configuration files. These are usually named nodemon.json.
An alternative local configuration file can be specified with the --config <file>
option.
see sample nodemon.json,
$ ./node_modules/nodemon/bin/nodemon.js app.js --config nodemon.json
[nodemon] 1.11.0
[nodemon] reading config /Users/userA/nodemon-example/nodemon.json
[nodemon] to restart at any time, enter `rs`
[nodemon] ignoring: .git .nyc_output .sass-cache bower_components coverage /Users/userA/nodemon-example/node_modules/**/* .git node_modules/**/node_modules
[nodemon] watching: test/fixtures/**/* test/samples/**/*
[nodemon] watching extensions: js,json
[nodemon] bind restart -> `osascript -e 'display notification "App restarted due to:
'$FILENAME'" with title "nodemon"'`
[nodemon] starting `node --harmony app.js`
[nodemon] child pid: 6166
[nodemon] watching 3 files
Example app listening on port 3000!
//package.json
"scripts": {"start": "node app.js","dev": "echo 'run dev' & npm start","test": "echo \"Error: no test specified\" && exit 1","nodemon": "./node_modules/nodemon/bin/nodemon.js --config nodemon.json --exec npm run dev "},
$ npm run nodemon
In nodemon.json
config file, define your own executables:
{ "execMap": { "pl": "perl" }}
In nodemon.json
config file, define action for event (Read more EventList) :
{"events": {"restart": "osascript -e 'display notification \"app restarted\" with title \"nodemon\"'"}}