1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- const querystring = require('querystring');
- function getAdditionalEntries({ devServer, options }) {
-
- let resourceQuery = {};
- if (devServer) {
- const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
- let { host, path, port } = devServer;
- let protocol = https || http2 ? 'https' : 'http';
- if (sockHost) host = sockHost;
- if (sockPath) path = sockPath;
- if (sockPort) port = sockPort;
- if (client && client.webSocketURL != null) {
- let parsedUrl = client.webSocketURL;
- if (typeof parsedUrl === 'string') parsedUrl = new URL(parsedUrl);
- let auth;
- if (parsedUrl.username) {
- auth = parsedUrl.username;
- if (parsedUrl.password) {
- auth += ':' + parsedUrl.password;
- }
- }
- if (parsedUrl.hostname != null) {
- host = [auth != null && auth, parsedUrl.hostname].filter(Boolean).join('@');
- }
- if (parsedUrl.pathname != null) {
- path = parsedUrl.pathname;
- }
- if (parsedUrl.port != null) {
- port = !['0', 'auto'].includes(String(parsedUrl.port)) ? parsedUrl.port : undefined;
- }
- if (parsedUrl.protocol != null) {
- protocol = parsedUrl.protocol !== 'auto' ? parsedUrl.protocol.replace(':', '') : 'ws';
- }
- }
- if (host) resourceQuery.sockHost = host;
- if (path) resourceQuery.sockPath = path;
- if (port) resourceQuery.sockPort = port;
- resourceQuery.sockProtocol = protocol;
- }
- if (options.overlay) {
- const { sockHost, sockPath, sockPort, sockProtocol } = options.overlay;
- if (sockHost) resourceQuery.sockHost = sockHost;
- if (sockPath) resourceQuery.sockPath = sockPath;
- if (sockPort) resourceQuery.sockPort = sockPort;
- if (sockProtocol) resourceQuery.sockProtocol = sockProtocol;
- }
-
- const queryString = querystring.stringify(resourceQuery, undefined, undefined, {
-
- encodeURIComponent(string) {
- return string;
- },
- });
- const prependEntries = [
-
- require.resolve('../../client/ReactRefreshEntry'),
- ];
- const overlayEntries = [
-
- options.overlay &&
- options.overlay.entry &&
- `${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ''}`,
- ].filter(Boolean);
- return { prependEntries, overlayEntries };
- }
- module.exports = getAdditionalEntries;
|