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