Skip to content

Commit

Permalink
fix pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtantay committed Jun 13, 2024
1 parent ae19d00 commit d4aa946
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/blocks/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ 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];

Expand All @@ -28,45 +25,41 @@ export function createScriptBlock(pathPrefix, source) {

if (shouldPreload) {
preloads.forEach((preload) => {
const preloadPath = [pathPrefix, preload].join('/');
const preloadUrl = new URL(preloadPath, pathSrc);
const preloadUrl = [basePath, pathPrefix, preload].join('/');
const resolvedPreload = resolve(pathPrefix, preload);
output.push(
`<link rel="preload" href="${
pathSrc ? preloadUrl : resolvedPreload
basePath ? preloadUrl : resolvedPreload
}" as="script" crossorigin>`
);
});
}

if (cssEntry) {
const cssEntryPath = [pathPrefix, cssEntry].join('/');
const cssEntryUrl = new URL(cssEntryPath, pathSrc);
const cssEntryUrl = [basePath, pathPrefix, cssEntry].join('/');
const resolvedCssEntry = resolve(pathPrefix, cssEntry);
output.push(
`<link rel="stylesheet" href="${
pathSrc ? cssEntryUrl : resolvedCssEntry
basePath ? cssEntryUrl : resolvedCssEntry
}">`
);
}

const modernEntryPath = [pathPrefix, modernEntry].join('/');
const modernEntryUrl = new URL(modernEntryPath, pathSrc);
const modernEntryUrl = [basePath, pathPrefix, modernEntry].join('/');
const resolvedModernEntry = resolve(pathPrefix, modernEntry);
output.push(
`<script type="module" src="${
pathSrc ? modernEntryUrl : resolvedModernEntry
basePath ? modernEntryUrl : resolvedModernEntry
}"></script>`
);

if ('legacy' in manifest) {
const legacyEntry = legacy[entry];
const legacyEntryPath = [pathPrefix, legacyEntry].join('/');
const legacyEntryUrl = new URL(legacyEntryPath, pathSrc);
const legacyEntryUrl = [basePath, pathPrefix, legacyEntry].join('/');
const resolvedLegacyEntry = resolve(pathPrefix, legacyEntry);
output.push(
`<script nomodule defer src="${
pathSrc ? legacyEntryUrl : resolvedLegacyEntry
basePath ? legacyEntryUrl : resolvedLegacyEntry
}"></script>`
);
}
Expand Down

0 comments on commit d4aa946

Please sign in to comment.