1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const webpack = require('webpack');
|
10 | const createDomain = require('./createDomain');
|
11 |
|
12 | function addEntries(config, options, server) {
|
13 | if (options.inline !== false) {
|
14 |
|
15 |
|
16 |
|
17 | const app = server || {
|
18 | address() {
|
19 | return { port: options.port };
|
20 | },
|
21 | };
|
22 |
|
23 | const domain = createDomain(options, app);
|
24 | const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
|
25 | const entries = [
|
26 | `${require.resolve('../../client/')}?${domain}${sockPath}`,
|
27 | ];
|
28 |
|
29 | if (options.hotOnly) {
|
30 | entries.push(require.resolve('webpack/hot/only-dev-server'));
|
31 | } else if (options.hot) {
|
32 | entries.push(require.resolve('webpack/hot/dev-server'));
|
33 | }
|
34 |
|
35 | const prependEntry = (entry) => {
|
36 | if (typeof entry === 'function') {
|
37 | return () => Promise.resolve(entry()).then(prependEntry);
|
38 | }
|
39 |
|
40 | if (typeof entry === 'object' && !Array.isArray(entry)) {
|
41 | const clone = {};
|
42 |
|
43 | Object.keys(entry).forEach((key) => {
|
44 | clone[key] = entries.concat(entry[key]);
|
45 | });
|
46 |
|
47 | return clone;
|
48 | }
|
49 |
|
50 | return entries.concat(entry);
|
51 | };
|
52 |
|
53 | [].concat(config).forEach((config) => {
|
54 | config.entry = prependEntry(config.entry || './src');
|
55 |
|
56 | if (options.hot || options.hotOnly) {
|
57 | config.plugins = config.plugins || [];
|
58 | if (
|
59 | !config.plugins.find(
|
60 | (plugin) =>
|
61 | plugin.constructor === webpack.HotModuleReplacementPlugin
|
62 | )
|
63 | ) {
|
64 | config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
65 | }
|
66 | }
|
67 | });
|
68 | }
|
69 | }
|
70 |
|
71 | module.exports = addEntries;
|