|
1 |
| -require('./check-versions')() |
| 1 | +require('./check-versions')(); |
2 | 2 |
|
3 |
| -const config = require('../config') |
| 3 | +const config = require('../config'); |
4 | 4 |
|
5 | 5 | if (!process.env.NODE_ENV) {
|
6 |
| - process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) |
| 6 | + process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV); |
7 | 7 | }
|
8 | 8 |
|
9 |
| -const open = require('open') |
10 |
| -const path = require('path') |
11 |
| -const chalk = require('chalk') |
12 |
| -const express = require('express') |
13 |
| -const webpack = require('webpack') |
14 |
| -const proxyMiddleware = require('http-proxy-middleware') |
| 9 | +const open = require('open'); |
| 10 | +const path = require('path'); |
| 11 | +const chalk = require('chalk'); |
| 12 | +const express = require('express'); |
| 13 | +const webpack = require('webpack'); |
| 14 | +const proxyMiddleware = require('http-proxy-middleware'); |
15 | 15 | const webpackDevMiddleware = require('webpack-dev-middleware');
|
16 | 16 | const webpackHotMiddleware = require('webpack-hot-middleware');
|
17 |
| -const webpackConfig = (process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production') |
18 |
| - ? require('./webpack.prod.conf') |
19 |
| - : require('./webpack.dev.conf') |
| 17 | +const webpackConfig = |
| 18 | + process.env.NODE_ENV === 'testing' || process.env.NODE_ENV === 'production' |
| 19 | + ? require('./webpack.prod.conf') |
| 20 | + : require('./webpack.dev.conf'); |
20 | 21 |
|
21 | 22 | // default port where dev server listens for incoming traffic
|
22 |
| -const port = process.env.PORT || config.dev.port |
| 23 | +const port = process.env.PORT || config.dev.port; |
23 | 24 | // automatically open browser, if not set will be false
|
24 |
| -const autoOpenBrowser = !!config.dev.autoOpenBrowser |
| 25 | +const autoOpenBrowser = !!config.dev.autoOpenBrowser; |
25 | 26 | // Define HTTP proxies to your custom API backend
|
26 | 27 | // https://github.com/chimurai/http-proxy-middleware
|
27 |
| -const proxyTable = config.dev.proxyTable |
| 28 | +const proxyTable = config.dev.proxyTable; |
28 | 29 |
|
29 |
| -const app = express() |
| 30 | +const app = express(); |
30 | 31 |
|
31 |
| -const compiler = webpack(webpackConfig) |
| 32 | +const compiler = webpack(webpackConfig); |
32 | 33 |
|
33 | 34 | const wdmInstance = webpackDevMiddleware(compiler, {
|
34 | 35 | publicPath: webpackConfig.output.publicPath,
|
35 |
| - quiet: true |
36 |
| -}) |
| 36 | + quiet: true, |
| 37 | +}); |
37 | 38 |
|
38 | 39 | const hotMiddleware = webpackHotMiddleware(compiler, {
|
39 | 40 | log: false,
|
40 |
| - heartbeat: 2000 |
41 |
| -}) |
| 41 | + heartbeat: 2000, |
| 42 | +}); |
42 | 43 |
|
43 | 44 | // force page reload when html-webpack-plugin template changes
|
44 | 45 | compiler.hooks.compilation.tap('html-webpack-plugin-after-emit', () => {
|
45 | 46 | hotMiddleware.publish({
|
46 |
| - action: 'reload' |
| 47 | + action: 'reload', |
47 | 48 | });
|
48 | 49 | });
|
49 | 50 |
|
50 | 51 | // proxy api requests
|
51 |
| -Object.keys(proxyTable).forEach((context) => { |
52 |
| - const options = proxyTable[context] |
| 52 | +Object.keys(proxyTable).forEach(context => { |
| 53 | + const options = proxyTable[context]; |
53 | 54 | if (typeof options === 'string') {
|
54 |
| - options = { target: options } |
| 55 | + options = { target: options }; |
55 | 56 | }
|
56 |
| - app.use(proxyMiddleware(options.filter || context, options)) |
57 |
| -}) |
| 57 | + app.use(proxyMiddleware(options.filter || context, options)); |
| 58 | +}); |
58 | 59 |
|
59 | 60 | // handle fallback for HTML5 history API
|
60 |
| -app.use(require('connect-history-api-fallback')()) |
| 61 | +app.use(require('connect-history-api-fallback')()); |
61 | 62 |
|
62 | 63 | // serve webpack bundle output
|
63 |
| -app.use(wdmInstance) |
| 64 | +app.use(wdmInstance); |
64 | 65 |
|
65 | 66 | // enable hot-reload and state-preserving
|
66 | 67 | // compilation error display
|
67 |
| -app.use(hotMiddleware) |
| 68 | +app.use(hotMiddleware); |
68 | 69 |
|
69 | 70 | // serve pure static assets
|
70 |
| -const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) |
71 |
| -app.use(staticPath, express.static('./static')) |
| 71 | +const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory); |
| 72 | +app.use(staticPath, express.static('./static')); |
72 | 73 |
|
73 |
| -module.exports = new Promise((resolve) => { |
74 |
| - console.log('> Starting dev server...') |
75 |
| - const server = app.listen(port, (err) => { |
| 74 | +module.exports = new Promise(resolve => { |
| 75 | + console.log('> Starting dev server...'); |
| 76 | + const server = app.listen(port, err => { |
76 | 77 | if (err) {
|
77 | 78 | console.error(err);
|
78 | 79 | }
|
79 | 80 |
|
80 | 81 | wdmInstance.waitUntilValid(() => {
|
81 |
| - const uri = 'http://localhost:' + port |
| 82 | + const uri = 'http://localhost:' + port; |
82 | 83 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
|
83 |
| - open(uri) |
84 |
| - console.log('> Listening at ' + uri + '\n') |
| 84 | + open(uri); |
| 85 | + console.log('> Listening at ' + uri + '\n'); |
85 | 86 | }
|
86 |
| - }) |
| 87 | + }); |
87 | 88 | });
|
88 | 89 |
|
89 | 90 | resolve({
|
|
0 commit comments