Last active
September 6, 2017 18:27
-
-
Save hackingbeauty/3654f5dae04abf9aa480d2823cc5e184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const express = require('express'); | |
const app = express(); | |
const isDevMode = process.env.NODE_ENV === 'development'; | |
const history = require('connect-history-api-fallback'); | |
app.use(require('morgan')('short')); | |
app.use(history()); | |
(function initWebpack() { | |
const webpack = require('webpack'); | |
const webpackConfig = require('./webpack/common.config'); | |
const compiler = webpack(webpackConfig); | |
app.use(require('webpack-dev-middleware')(compiler, { | |
noInfo: true, publicPath: webpackConfig.output.publicPath, | |
})); | |
app.use(require('webpack-hot-middleware')(compiler, { | |
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000, | |
})); | |
app.use(express.static(__dirname + '/')); | |
})(); | |
app.get(/.*/, function root(req, res) { | |
res.sendFile(__dirname + '/src/index.html'); | |
}); | |
const server = http.createServer(app); | |
server.listen(process.env.PORT || 3000, function onListen() { | |
const address = server.address(); | |
console.log('Listening on: %j', address); | |
console.log(' -> that probably means: http://localhost:%d', address.port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment