Skip to content

Commit

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

Expand All @@ -26,44 +28,44 @@ 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(
`<link rel="preload" href="${
basePath ? preloadUrl : resolvedPreload
pathSrc ? preloadUrl : resolvedPreload
}" as="script" crossorigin>`
);
});
}

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(
`<link rel="stylesheet" href="${
basePath ? cssEntryUrl : resolvedCssEntry
pathSrc ? cssEntryUrl : resolvedCssEntry
}">`
);
}

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

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(
`<script nomodule defer src="${
basePath ? legacyEntryUrl : resolvedLegacyEntry
pathSrc ? legacyEntryUrl : resolvedLegacyEntry
}"></script>`
);
}
Expand Down

0 comments on commit c4ea322

Please sign in to comment.