1/** 2 * Copyright © 2022 650 Industries. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 */ 7 8export function buildUrlForBundle(bundlePath: string): string { 9 if (process.env.NODE_ENV === 'production') { 10 if (typeof location !== 'undefined') { 11 return joinComponents(location.origin, bundlePath); 12 } 13 throw new Error( 14 'Unable to determine the production URL where additional JavaScript chunks are hosted because the global "location" variable is not defined.' 15 ); 16 } else { 17 const getDevServer = require('../getDevServer') 18 .default as typeof import('../getDevServer').default; 19 20 const { url: serverUrl } = getDevServer(); 21 22 return joinComponents(serverUrl, bundlePath); 23 } 24} 25 26function joinComponents(prefix: string, suffix: string): string { 27 return prefix.replace(/\/+$/, '') + '/' + suffix.replace(/^\/+/, ''); 28} 29