Skip to content

Instantly share code, notes, and snippets.

@ezekielchentnik
Last active December 14, 2016 10:39
Show Gist options
  • Save ezekielchentnik/ed0cabb09bf29e5b4a7a461a11b1c63d to your computer and use it in GitHub Desktop.
Save ezekielchentnik/ed0cabb09bf29e5b4a7a461a11b1c63d to your computer and use it in GitHub Desktop.
import express from 'express';
const app = express();
if (IS_DEV) {
require('piping')();
}
//express routes, etc.
export default app;
import app from './app';
var PORT = 8080;
var httpServer = app.listen(PORT, () => {
console.log(`Micro-App on http://localhost:${PORT} [${app.settings.env}]`);
});
process.on('SIGTERM', () => {
httpServer.close(() => {
process.exit(0);
});
});
import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from './webpack.client.babel';
const app = express();
const PORT = 8081;
const webpackCompiler = webpack(webpackConfig);
const serverOptions = {
contentBase: 'http://localhost:' + PORT,
quiet: true,
noInfo: true,
hot: true,
inline: true,
lazy: false,
publicPath: webpackConfig.output.publicPath,
headers: {'Access-Control-Allow-Origin': '*'},
stats: { colors: true }
};
app.use(webpackDevMiddleware(webpackCompiler, serverOptions));
app.use(webpackHotMiddleware(webpackCompiler));
const httpServer = app.listen(PORT, () => {
console.log(`HMR server on http://localhost:${PORT} [${app.settings.env}]`);
});
process.on('SIGTERM', () => {
httpServer.close(() => {
process.exit(0);
});
});
//webpack stuff
entry: {
main: IS_DEV ? [
'webpack-hot-middleware/client?path=http://localhost:8081/__webpack_hmr', //same port as your webpack-dev-server.js
'./client/js/index.js'
] : [
'./client/js/index.js'
]
},
@dlebedynskyi
Copy link

Can you also show how do start everything together?
I believe you just spawn both webpack-dev-server.js and server.js ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment