fix: runtimeJS support on windows (#64)
This commit is contained in:
+4
-1
@@ -64,7 +64,7 @@ async function init(directory: string) {
|
|||||||
)}";\n`;
|
)}";\n`;
|
||||||
await Deno.writeTextFile(join(directory, "deps.ts"), DEPS_TS);
|
await Deno.writeTextFile(join(directory, "deps.ts"), DEPS_TS);
|
||||||
const PAGES_INDEX_TSX = `/** @jsx h */
|
const PAGES_INDEX_TSX = `/** @jsx h */
|
||||||
import { h, IS_BROWSER, useState } from "../deps.ts";
|
import { h, IS_BROWSER, PageConfig, useState } from "../deps.ts";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
@@ -93,6 +93,9 @@ function Counter() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const config: PageConfig = { runtimeJS: true };
|
||||||
|
|
||||||
`;
|
`;
|
||||||
await Deno.writeTextFile(
|
await Deno.writeTextFile(
|
||||||
join(directory, "pages", "index.tsx"),
|
join(directory, "pages", "index.tsx"),
|
||||||
|
|||||||
+11
-5
@@ -1,4 +1,4 @@
|
|||||||
import { denoPlugin, esbuild, esbuildTypes } from "./deps.ts";
|
import { denoPlugin, esbuild, esbuildTypes, toFileUrl } from "./deps.ts";
|
||||||
import { Page } from "./types.ts";
|
import { Page } from "./types.ts";
|
||||||
|
|
||||||
let esbuildInitalized: boolean | Promise<void> = false;
|
let esbuildInitalized: boolean | Promise<void> = false;
|
||||||
@@ -36,7 +36,7 @@ export class Bundler {
|
|||||||
entryPoints[page.name] = `fresh:///${page.name}`;
|
entryPoints[page.name] = `fresh:///${page.name}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const absWorkingDir = Deno.cwd();
|
||||||
await ensureEsbuildInialized();
|
await ensureEsbuildInialized();
|
||||||
const bundle = await esbuild.build({
|
const bundle = await esbuild.build({
|
||||||
bundle: true,
|
bundle: true,
|
||||||
@@ -44,7 +44,10 @@ export class Bundler {
|
|||||||
format: "esm",
|
format: "esm",
|
||||||
metafile: true,
|
metafile: true,
|
||||||
minify: true,
|
minify: true,
|
||||||
outdir: `/`,
|
outdir: ".",
|
||||||
|
// This is requried to ensure the format of the outputFiles path is the same
|
||||||
|
// between windows and linux
|
||||||
|
absWorkingDir,
|
||||||
outfile: "",
|
outfile: "",
|
||||||
platform: "neutral",
|
platform: "neutral",
|
||||||
plugins: [freshPlugin(this.#pages), denoPlugin()],
|
plugins: [freshPlugin(this.#pages), denoPlugin()],
|
||||||
@@ -53,7 +56,6 @@ export class Bundler {
|
|||||||
treeShaking: true,
|
treeShaking: true,
|
||||||
write: false,
|
write: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const metafileOutputs = bundle.metafile!.outputs;
|
const metafileOutputs = bundle.metafile!.outputs;
|
||||||
|
|
||||||
for (const path in metafileOutputs) {
|
for (const path in metafileOutputs) {
|
||||||
@@ -65,8 +67,12 @@ export class Bundler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cache = new Map<string, Uint8Array>();
|
const cache = new Map<string, Uint8Array>();
|
||||||
|
const absDirUrlLength = toFileUrl(absWorkingDir).href.length;
|
||||||
for (const file of bundle.outputFiles) {
|
for (const file of bundle.outputFiles) {
|
||||||
cache.set(file.path, file.contents);
|
cache.set(
|
||||||
|
toFileUrl(file.path).href.substring(absDirUrlLength),
|
||||||
|
file.contents,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.#cache = cache;
|
this.#cache = cache;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user