feat(server): Add basePath config to host from a directory (#2092)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Reed von Redwitz
2023-11-29 16:44:25 +00:00
committed by GitHub
co-authored by Marvin Hagemeister
parent fe792455ab
commit 9ab8651018
40 changed files with 810 additions and 28 deletions
+28
View File
@@ -20,6 +20,7 @@ export interface EsbuildBuilderOptions {
jsxImportSource?: string;
target: string | string[];
absoluteWorkingDir: string;
basePath?: string;
}
export class EsbuildBuilder implements Builder {
@@ -94,6 +95,7 @@ export class EsbuildBuilder implements Builder {
metafile: true,
plugins: [
devClientUrlPlugin(opts.basePath),
buildIdPlugin(opts.buildID),
...denoPlugins({ configPath: opts.configPath }),
],
@@ -128,6 +130,32 @@ export class EsbuildBuilder implements Builder {
}
}
function devClientUrlPlugin(basePath?: string): Plugin {
return {
name: "dev-client-url",
setup(build) {
build.onLoad(
{ filter: /client\.ts$/, namespace: "file" },
async (args) => {
// Load the original script
const contents = await Deno.readTextFile(args.path);
// Replace the URL
const modifiedContents = contents.replace(
"/_frsh/alive",
`${basePath}/_frsh/alive`,
);
return {
contents: modifiedContents,
loader: "ts",
};
},
);
},
};
}
function buildIdPlugin(buildId: string): Plugin {
const file = import.meta.resolve("../runtime/build_id.ts");
const url = new URL(file);