Skip to content

Commit

Permalink
Merge pull request #489 from chentsulin/fix-issue-488
Browse files Browse the repository at this point in the history
Fixed issue #488: `npm run dev` race condition
  • Loading branch information
jhen0409 authored Oct 31, 2016
2 parents ffc3347 + d1ec63c commit eafd949
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"test-watch": "npm test -- --watch",
"test-e2e": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 mocha --retries 2 --compilers js:babel-register --require ./test/setup.js ./test/e2e.js",
"lint": "eslint --ignore-path .gitignore --format=node_modules/eslint-formatter-pretty app test *.js",
"hot-server": "cross-env NODE_ENV=development node -r babel-register server.js",
"hot-server": "cross-env NODE_ENV=development node --max_old_space_size=2096 -r babel-register server.js",
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.electron.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.production.js --progress --profile --colors",
"build": "npm run build-main && npm run build-renderer",
"start": "cross-env NODE_ENV=production electron ./app/",
"start-hot": "cross-env HOT=1 NODE_ENV=development electron -r babel-register -r babel-polyfill ./app/main.development",
"postinstall": "concurrently \"install-app-deps\" \"node node_modules/fbjs-scripts/node/check-dev-engines.js package.json\"",
"dev": "concurrently --kill-others \"npm run hot-server\" \"npm run start-hot\"",
"dev": "npm run hot-server -- --start-hot",
"package": "npm run build && build --publish never",
"package-win": "npm run build && build --win --x64",
"package-linux": "npm run build && build --linux",
Expand Down
16 changes: 12 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import { spawn } from 'child_process';

import config from './webpack.config.development';

const argv = require('minimist')(process.argv.slice(2));

const app = express();
const compiler = webpack(config);
const PORT = process.env.PORT || 3000;
Expand All @@ -27,10 +30,15 @@ app.use(wdm);

app.use(webpackHotMiddleware(compiler));

const server = app.listen(PORT, 'localhost', err => {
if (err) {
console.error(err);
return;
const server = app.listen(PORT, 'localhost', serverError => {
if (serverError) {
return console.error(serverError);
}

if (argv['start-hot']) {
spawn('npm', ['run', 'start-hot'], { env: process.env, stdio: 'inherit' })
.on('close', code => process.exit(code))
.on('error', spawnError => console.error(spawnError));
}

console.log(`Listening at http://localhost:${PORT}`);
Expand Down

0 comments on commit eafd949

Please sign in to comment.