-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
30 lines (24 loc) · 773 Bytes
/
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
const express = require('express')
const webpack = require('webpack')
const path = require('path')
const PORT = process.env.PORT || 3000
const app = express()
if (process.env.NODE_ENV === 'development') {
const config = require('./webpack.config.dev')
const compiler = webpack(config)
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}))
app.use(require('webpack-hot-middleware')(compiler))
app.use('/images', express.static(path.join(__dirname, '/images')))
} else {
app.use('/', express.static(path.join(__dirname, '/dist')))
}
app.listen(PORT, 'localhost', (err) => {
if (err) {
console.error(err)
return
}
console.log(`server initialized at http://localhost:${PORT}`)
})