fix: buildIdPlugin breaks when Fresh is hosted (#1230)
Only file:// URLs were supported previously, which breaks if you are importing Fresh via HTTPS URLs.
This commit is contained in:
+10
-2
@@ -170,12 +170,20 @@ export class Bundler {
|
|||||||
function buildIdPlugin(buildId: string): esbuildTypes.Plugin {
|
function buildIdPlugin(buildId: string): esbuildTypes.Plugin {
|
||||||
const file = import.meta.resolve("../runtime/build_id.ts");
|
const file = import.meta.resolve("../runtime/build_id.ts");
|
||||||
const url = new URL(file);
|
const url = new URL(file);
|
||||||
const path = fromFileUrl(url);
|
let options: esbuildTypes.OnLoadOptions;
|
||||||
|
if (url.protocol === "file:") {
|
||||||
|
const path = fromFileUrl(url);
|
||||||
|
options = { filter: new RegExp(escape(path)), namespace: "file" };
|
||||||
|
} else {
|
||||||
|
const namespace = url.protocol.slice(0, -1);
|
||||||
|
const path = url.href.slice(namespace.length + 1);
|
||||||
|
options = { filter: new RegExp(escape(path)), namespace };
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
name: "fresh-build-id",
|
name: "fresh-build-id",
|
||||||
setup(build) {
|
setup(build) {
|
||||||
build.onLoad(
|
build.onLoad(
|
||||||
{ filter: new RegExp(escape(path)), namespace: "file" },
|
options,
|
||||||
() => ({ contents: `export const BUILD_ID = "${buildId}";` }),
|
() => ({ contents: `export const BUILD_ID = "${buildId}";` }),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user