-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (36 loc) · 1.08 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import express from 'express'
const app = new express()
const port = 3000
console.log('Environment: ' + process.env.NODE_ENV)
const isProductionEnv = process.env.NODE_ENV === 'production'
if (!isProductionEnv) {
const config = require('./webpack.config')
const compiler = require('webpack')(config)
app.use(require('webpack-hot-middleware')(compiler))
app.use(require('webpack-dev-middleware')(compiler, {
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
},
publicPath: config.output.publicPath
}))
} else {
// in production setting webpack build result has to be exposed manually
app.get('/dist/client.js', function(req, res) {
res.status(200).sendFile(__dirname + '/dist/client.js')
})
}
app.get('/', function(req, res) {
res.status(200).sendFile(__dirname + '/src/index.html')
})
app.listen(port, function(error) {
if (error) {
console.error(error)
} else {
console.info('==> Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port)
}
})