1 | var express = require('express')
|
2 | var webpack = require('webpack')
|
3 | var config = require('./webpack.dev.conf')
|
4 | var proxyMiddleware = require('http-proxy-middleware')
|
5 | var httpProxy = require('http-proxy')
|
6 |
|
7 | var app = express()
|
8 | var compiler = webpack(config)
|
9 | var proxy = httpProxy.createProxyServer({proxyTimeout: 600000})
|
10 |
|
11 |
|
12 |
|
13 | var proxyTable = {
|
14 | '/rs': {
|
15 | target: 'http://127.0.0.1:5001'
|
16 | }
|
17 | }
|
18 |
|
19 | var devMiddleware = require('webpack-dev-middleware')(compiler, {
|
20 | publicPath: config.output.publicPath,
|
21 | stats: {
|
22 | colors: true,
|
23 | chunks: false
|
24 | }
|
25 | })
|
26 |
|
27 | var hotMiddleware = require('webpack-hot-middleware')(compiler)
|
28 |
|
29 | compiler.plugin('compilation', function (compilation) {
|
30 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
|
31 | hotMiddleware.publish({ action: 'reload' })
|
32 | cb()
|
33 | })
|
34 | })
|
35 |
|
36 |
|
37 | Object.keys(proxyTable).forEach(function (context) {
|
38 | var options = proxyTable[context]
|
39 | if (typeof options === 'string') {
|
40 | options = { target: options }
|
41 | }
|
42 | app.use(proxyMiddleware(context, options))
|
43 | })
|
44 |
|
45 |
|
46 | app.use(require('connect-history-api-fallback')())
|
47 |
|
48 |
|
49 | app.use(devMiddleware)
|
50 |
|
51 |
|
52 |
|
53 | app.use(hotMiddleware)
|
54 |
|
55 |
|
56 | app.use('/static', express.static('./static'))
|
57 |
|
58 | module.exports = app.listen(8083, function (err) {
|
59 | if (err) {
|
60 | console.log(err)
|
61 | return
|
62 | }
|
63 | console.log('Listening at http://localhost:8083')
|
64 | })
|