Skip to content

Instantly share code, notes, and snippets.

@moizhb
Created January 17, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moizhb/5be2fd828bfce60a0902db90ab58161b to your computer and use it in GitHub Desktop.
Save moizhb/5be2fd828bfce60a0902db90ab58161b to your computer and use it in GitHub Desktop.
const path = require('path');
const express = require('express');
const webpack = require('webpack');
const config = require('./webpack.config.dev');
const app = express();
const compiler = webpack(config);
const host = 'http://localhost';
const port = process.env.npm_config_port ? process.env.npm_config_port : 3000;
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(port, 'localhost', (err) => {
if (err) {
console.log(err);
return;
}
console.info('==> Listening on port %s. Open up %s:%s/ in your browser.', port, host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment