Replaced the dev script with webpack-watch-server.

This commit is contained in:
Jayden Seric 2017-04-04 02:37:50 +10:00
parent 91896891ad
commit 5a67bc642b
2 changed files with 3 additions and 54 deletions

View File

@ -21,15 +21,13 @@
"zoo": "^0.1.9"
},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-eslint": "^7.2.1",
"chalk": "^1.1.3",
"indent-string": "^3.1.0",
"standard": "^9.0.2"
"standard": "^9.0.2",
"webpack-watch-server": "^1.0.0"
},
"scripts": {
"lint": "standard",
"dev": "zoo babel-node scripts/dev",
"dev": "zoo webpack-watch-server",
"build": "zoo webpack",
"start": "zoo node dist"
},

View File

@ -1,49 +0,0 @@
import 'source-map-support/register'
import {spawn} from 'child_process'
import chalk from 'chalk'
import indentString from 'indent-string'
import webpack from 'webpack'
import webpackConfig from '../webpack.config.babel'
let serverProcess
let wasServerMessage
function startServer () {
serverProcess = spawn('node', [webpackConfig.output.path])
serverProcess.stdout.on('data', data => {
console.log((wasServerMessage ? '' : '\n') + indentString(chalk.white(data), 4))
wasServerMessage = true
})
serverProcess.stderr.on('data', data => {
console.error((wasServerMessage ? '' : '\n') + indentString(chalk.red(data), 4))
wasServerMessage = true
})
}
function stopServer () {
if (serverProcess) serverProcess.kill()
}
const compiler = webpack(webpackConfig)
const watcher = compiler.watch({}, (errors, stats) => {
const hasErrors = errors || stats.hasErrors()
console[hasErrors ? 'error' : 'log']((stats.toString('minimal')))
wasServerMessage = false
stopServer()
if (!hasErrors) startServer()
})
function exit () {
watcher.close()
stopServer()
}
;[
'SIGINT',
'SIGTERM',
'SIGHUP',
'SIGQUIT',
'exit',
'uncaughtException'
].forEach(event => process.on(event, exit))