forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddDevServerEntrypoints.js
35 lines (30 loc) · 1.36 KB
/
addDevServerEntrypoints.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
/* eslint no-param-reassign: 'off' */
const createDomain = require('./createDomain');
module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptions, listeningApp) {
if (devServerOptions.inline !== false) {
// we're stubbing the app in this method as it's static and doesn't require
// a listeningApp to be supplied. createDomain requires an app with the
// address() signature.
const app = listeningApp || {
address() {
return { port: devServerOptions.port };
}
};
const domain = createDomain(devServerOptions, app);
const sockPath = devServerOptions.sockPath ? `&sockPath=${devServerOptions.sockPath}` : '';
const devClient = [`${require.resolve('../../client/')}?${domain}${sockPath}`];
if (devServerOptions.hotOnly) { devClient.push('webpack/hot/only-dev-server'); } else if (devServerOptions.hot) { devClient.push('webpack/hot/dev-server'); }
[].concat(webpackOptions).forEach((wpOpt) => {
if (typeof wpOpt.entry === 'object' && !Array.isArray(wpOpt.entry)) {
Object.keys(wpOpt.entry).forEach((key) => {
wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]);
});
} else if (typeof wpOpt.entry === 'function') {
wpOpt.entry = wpOpt.entry(devClient);
} else {
wpOpt.entry = devClient.concat(wpOpt.entry);
}
});
}
};