Skip to content

Commit

Permalink
fix: basePathVar and runtimeId options (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Nov 13, 2023
1 parent 0aacc63 commit 0601f65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-ravens-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Fix regression when setting basePathVar in dev mode and runtimeId.
10 changes: 4 additions & 6 deletions src/render-assets-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export function getRenderAssetsRuntime(opts: {
basePathVar?: string;
}): string {
return `${
!opts.basePathVar
? "const base = import.meta.env.BASE_URL;"
: `const base = globalThis.${opts.basePathVar};
opts.basePathVar && opts.isBuild
? `const base = globalThis.${opts.basePathVar};
if (typeof base !== "string") throw new Error("${opts.basePathVar} must be defined when using basePathVar.");
if (!base.endsWith("/")) throw new Error("${opts.basePathVar} must end with a '/' when using basePathVar.");`
: "const base = import.meta.env.BASE_URL;"
}
export function addAssets(g, newEntries) {
const entries = g.___viteEntries;
Expand All @@ -21,9 +21,7 @@ export function addAssets(g, newEntries) {
g.___viteInjectAttrs = g.cspNonce
? \` nonce="\${g.cspNonce.replace(/"/g, "'")}"\`
: "";
${
opts.runtimeId ? `$ g.runtimeId = ${JSON.stringify(opts.runtimeId)};` : ""
}
${opts.runtimeId ? `g.runtimeId = ${JSON.stringify(opts.runtimeId)};` : ""}
}
}
Expand Down

0 comments on commit 0601f65

Please sign in to comment.