diff --git a/lib/blocks/script.js b/lib/blocks/script.js index f45d3eda..d5fda8c9 100644 --- a/lib/blocks/script.js +++ b/lib/blocks/script.js @@ -12,6 +12,8 @@ export function createScriptBlock(pathPrefix, source) { const { manifest } = source; const { basePath, modern, css, preloads, legacy } = manifest; + const pathSrc = basePath && basePath !== 'http://localhost:3000' ? basePath : ''; + const modernEntry = modern[entry]; const cssEntry = css[entry]; @@ -26,11 +28,11 @@ export function createScriptBlock(pathPrefix, source) { if (shouldPreload) { preloads.forEach((preload) => { const preloadPath = [pathPrefix, preload].join('/'); - const preloadUrl = new URL(preloadPath, basePath); + const preloadUrl = new URL(preloadPath, pathSrc); const resolvedPreload = resolve(pathPrefix, preload); output.push( `` ); }); @@ -38,32 +40,32 @@ export function createScriptBlock(pathPrefix, source) { if (cssEntry) { const cssEntryPath = [pathPrefix, cssEntry].join('/'); - const cssEntryUrl = new URL(cssEntryPath, basePath); + const cssEntryUrl = new URL(cssEntryPath, pathSrc); const resolvedCssEntry = resolve(pathPrefix, cssEntry); output.push( `` ); } const modernEntryPath = [pathPrefix, modernEntry].join('/'); - const modernEntryUrl = new URL(modernEntryPath, basePath); + const modernEntryUrl = new URL(modernEntryPath, pathSrc); const resolvedModernEntry = resolve(pathPrefix, modernEntry); output.push( `` ); if ('legacy' in manifest) { const legacyEntry = legacy[entry]; const legacyEntryPath = [pathPrefix, legacyEntry].join('/'); - const legacyEntryUrl = new URL(legacyEntryPath, basePath); + const legacyEntryUrl = new URL(legacyEntryPath, pathSrc); const resolvedLegacyEntry = resolve(pathPrefix, legacyEntry); output.push( `` ); }