-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.dev-server.js
More file actions
48 lines (40 loc) · 1.07 KB
/
webpack.dev-server.js
File metadata and controls
48 lines (40 loc) · 1.07 KB
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
41
42
43
44
45
46
47
48
import express from 'express'
import bodyParser from 'body-parser'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import webpackConfig from './webpack.config'
process.env.NODE_ENV = 'development'
const IP = process.env.IP || 'localhost'
const PORT = process.env.PORT || 4000
const server = express()
const compiler = webpack(webpackConfig)
server.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true,
hash: false,
version: false,
chunks: false,
children: false
}
})
)
server.use(
webpackHotMiddleware(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000
})
)
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({ extended: true }))
server.listen(PORT, IP, err => {
if (err) {
console.log(`=> OMG!!! 🙀 ${err}`)
}
console.log(`=> 🔥 Webpack dev server is running on port ${PORT}`)
})