Skip to content

Commit

Permalink
wip: on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl committed Apr 21, 2023
1 parent d060c34 commit 7a33916
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
25 changes: 14 additions & 11 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let islands = await get_islands(site_dir);
await ensureDir(build_dir);

const ESBuildConfig: esbuild.BuildOptions = {
entryPoints: ["mononykus", ...islands],
// entryPoints: ["mononykus", ...islands],
write: false,
plugins: [
mononykus(site_dir),
Expand All @@ -64,22 +64,25 @@ const ESBuildConfig: esbuild.BuildOptions = {
format: "esm",
minify: !flags.dev,
bundle: true,
splitting: true,
metafile: true,
// splitting: true,
// metafile: true,
outdir: build_dir,
};

const copy_assets = async () =>
await copy(site_dir + "assets", build_dir + "assets", { overwrite: true });

let context = await esbuild.context({
await esbuild.build({
...ESBuildConfig,
entryPoints: ["mononykus", ...islands],
entryPoints: [site_dir + "routes/index.svelte"],
});

const rebuild = async () => {
await Promise.all([
context.rebuild(),
esbuild.build({
...ESBuildConfig,
entryPoints: [site_dir + "routes/index.svelte"],
}),
copy_assets(),
]);
};
Expand All @@ -103,12 +106,12 @@ if (flags.dev) {
) {
const new_islands = await get_islands(site_dir);
if (new_islands.some((island) => !islands.includes(island))) {
await context.dispose();
// await context.dispose();
islands = new_islands;
context = await esbuild.context({
...ESBuildConfig,
entryPoints: ["mononykus", ...islands],
});
// context = await esbuild.context({
// ...ESBuildConfig,
// entryPoints: ["mononykus", ...islands],
// });
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/esbuild_plugins/build_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export const build_routes = (

const module = await import(
"data:application/javascript," + encodeURIComponent(routes.text)
) as {
routes: Array<{
path: string;
render(): SSROutput;
}>;
islands: Array<unknown>;
};
) as any;
// ) as {
// routes: Array<{
// path: string;
// render(): SSROutput;
// }>;
// islands: Array<unknown>;
// };

// await Promise.all([
// ...module.routes.map(async ({ path, render }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/esbuild_plugins/mononykus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const get_routes = async (site_dir: string) => {

const filter = /^mononykus$/;

const name = (basename: string) =>
export const name = (basename: string) =>
basename
.replace(/(\.island)?\.svelte$/, "")
.replaceAll(/(\.|\W)/g, "_");
Expand Down

0 comments on commit 7a33916

Please sign in to comment.