|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | /* eslint-disable |
| 4 | + no-shadow, |
4 | 5 | no-param-reassign, |
| 6 | + array-bracket-spacing, |
5 | 7 | space-before-function-paren |
6 | 8 | */ |
7 | 9 | const createDomain = require('./createDomain'); |
8 | 10 |
|
9 | | -function addEntries (webpackOptions, devServerOptions, server) { |
10 | | - if (devServerOptions.inline !== false) { |
| 11 | +function addEntries (config, options, server) { |
| 12 | + if (options.inline !== false) { |
11 | 13 | // we're stubbing the app in this method as it's static and doesn't require |
12 | 14 | // a server to be supplied. createDomain requires an app with the |
13 | 15 | // address() signature. |
14 | 16 | const app = server || { |
15 | 17 | address() { |
16 | | - return { port: devServerOptions.port }; |
| 18 | + return { port: options.port }; |
17 | 19 | } |
18 | 20 | }; |
19 | 21 |
|
20 | | - const domain = createDomain(devServerOptions, app); |
21 | | - const devClient = [`${require.resolve('../../client/')}?${domain}`]; |
| 22 | + const domain = createDomain(options, app); |
| 23 | + const entries = [ `${require.resolve('../../client/')}?${domain}` ]; |
22 | 24 |
|
23 | | - if (devServerOptions.hotOnly) { |
24 | | - devClient.push(require.resolve('webpack/hot/only-dev-server')); |
25 | | - } else if (devServerOptions.hot) { |
26 | | - devClient.push(require.resolve('webpack/hot/dev-server')); |
| 25 | + if (options.hotOnly) { |
| 26 | + entries.push(require.resolve('webpack/hot/only-dev-server')); |
| 27 | + } else if (options.hot) { |
| 28 | + entries.push(require.resolve('webpack/hot/dev-server')); |
27 | 29 | } |
28 | 30 |
|
29 | | - const prependDevClient = (entry) => { |
| 31 | + const prependEntry = (entry) => { |
30 | 32 | if (typeof entry === 'function') { |
31 | | - return () => Promise.resolve(entry()).then(prependDevClient); |
| 33 | + return () => Promise.resolve(entry()).then(prependEntry); |
32 | 34 | } |
33 | 35 |
|
34 | 36 | if (typeof entry === 'object' && !Array.isArray(entry)) { |
35 | | - const entryClone = {}; |
| 37 | + const clone = {}; |
36 | 38 |
|
37 | 39 | Object.keys(entry).forEach((key) => { |
38 | | - entryClone[key] = devClient.concat(entry[key]); |
| 40 | + clone[key] = entries.concat(entry[key]); |
39 | 41 | }); |
40 | 42 |
|
41 | | - return entryClone; |
| 43 | + return clone; |
42 | 44 | } |
43 | 45 |
|
44 | | - return devClient.concat(entry); |
| 46 | + return entries.concat(entry); |
45 | 47 | }; |
46 | 48 |
|
47 | | - [].concat(webpackOptions).forEach((wpOpt) => { |
48 | | - wpOpt.entry = prependDevClient(wpOpt.entry || './src'); |
| 49 | + [].concat(config).forEach((config) => { |
| 50 | + config.entry = prependEntry(config.entry || './src'); |
49 | 51 | }); |
50 | 52 | } |
51 | 53 | } |
|
0 commit comments