diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 94f93ce..bd8d4dd 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -47,7 +47,7 @@ jobs:
with:
project: mononykus
entrypoint: https://deno.land/std@0.183.0/http/file_server.ts
- root: src/_site/build
+ root: build
gh:
if: github.ref_name == 'main'
@@ -80,7 +80,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
- path: src/_site/build
+ path: build
- name: Deploy to GitHub Pages
id: deployment
diff --git a/src/_site/routes/index.svelte b/src/_site/routes/index.svelte
index bb3153e..d5c757f 100644
--- a/src/_site/routes/index.svelte
+++ b/src/_site/routes/index.svelte
@@ -3,9 +3,18 @@
import HelloFriend from "../components/HelloFriend.island.svelte";
import Counter from "../components/Counter.island.svelte";
import Body from "../components/Body.svelte";
+
+ export let base_path = "/";
-Mononykus â Deno + Svelte
+
+ Mononykus â Deno + Svelte
+
+
diff --git a/src/build.ts b/src/build.ts
index 65d1369..5418468 100644
--- a/src/build.ts
+++ b/src/build.ts
@@ -9,6 +9,9 @@ import { walk } from "https://deno.land/std@0.177.0/fs/walk.ts";
import { create_handler } from "./server.ts";
import { globToRegExp } from "https://deno.land/std@0.182.0/path/glob.ts";
import { copy } from "https://deno.land/std@0.179.0/fs/copy.ts";
+import { resolve } from "https://deno.land/std@0.177.0/path/mod.ts";
+import { normalize as normalise } from "https://deno.land/std@0.177.0/path/posix.ts"; // the web is posix
+import { bold, underline } from "https://deno.land/std@0.177.0/fmt/colors.ts";
const flags = parse(Deno.args, {
string: ["site", "build", "base"],
@@ -16,16 +19,11 @@ const flags = parse(Deno.args, {
default: { site: "_site/", dev: false, base: "/" },
});
-const site_dir = flags.site.replace(/\/?$/, "/");
-const build_dir = (flags.build ?? `${site_dir}build/`).replace(/\/?$/, "/");
-const base_path = flags.base.replace(/\/?$/, "/");
+const site_dir = resolve(flags.site);
+const build_dir = resolve(flags.build ?? "build");
+const base_path = normalise("/" + flags.base + "/");
-// clean out old builds, if they exist
-try {
- await Deno.remove(build_dir, { recursive: true });
-} catch (_error) {
- // do nothing
-}
+console.info("ðŠķ", " â ", bold("Mononykus"));
export const get_svelte_files = async ({
dir,
@@ -35,10 +33,10 @@ export const get_svelte_files = async ({
const glob = (glob: string) => globToRegExp(glob, { globstar: true });
const files: string[] = [];
for await (
- const { path } of walk(site_dir + dir, {
+ const { path } of walk(resolve(site_dir, dir), {
match: [
- glob(site_dir + "/routes/**/*.svelte"),
- glob(site_dir + "/components/**/*.island.svelte"),
+ glob(resolve(site_dir, "routes") + "/**/*.svelte"),
+ glob(resolve(site_dir, "components") + "/**/*.island.svelte"),
],
includeDirs: false,
})
@@ -48,10 +46,8 @@ export const get_svelte_files = async ({
return files;
};
-await ensureDir(build_dir);
-
const baseESBuildConfig = {
- logLevel: "info",
+ logLevel: "silent",
format: "esm",
minify: !flags.dev,
bundle: true,
@@ -76,15 +72,31 @@ const islandsESBuildConfig: esbuild.BuildOptions = {
svelte_components,
svelte_internal,
],
- outdir: build_dir + "components/",
+ outdir: resolve(build_dir, "components/"),
splitting: true,
...baseESBuildConfig,
};
+const prepare = async () => {
+ try {
+ await Deno.remove(build_dir, { recursive: true });
+ } catch (_error) {
+ // do nothing
+ }
+
+ await ensureDir(build_dir);
+};
+
const copy_assets = async () =>
- await copy(site_dir + "assets", build_dir + "assets", { overwrite: true });
+ await copy(
+ resolve(site_dir, "assets"),
+ resolve(build_dir, "assets"),
+ {
+ overwrite: true,
+ },
+ );
-const rebuild = async () => {
+const build = async () => {
await Promise.all([
esbuild.build(routesESBuildConfig),
esbuild.build(islandsESBuildConfig),
@@ -92,7 +104,8 @@ const rebuild = async () => {
]);
};
-await rebuild();
+await prepare();
+await build();
if (flags.dev) {
const watcher = Deno.watchFs(site_dir);
@@ -102,9 +115,14 @@ if (flags.dev) {
if (path && (kind === "modify" || kind === "create")) {
if (path.includes(build_dir)) continue;
clearTimeout(timeout);
- timeout = setTimeout(rebuild, 6);
+ timeout = setTimeout(build, 6);
}
}
-} else {
- Deno.exit(0);
}
+
+console.info("\nServe the following directory:");
+console.info(underline(build_dir));
+
+// Ensure that we exit promptly,
+// without waiting for any async code in SSR islands
+Deno.exit(0);
diff --git a/src/esbuild_plugins/routes.ts b/src/esbuild_plugins/routes.ts
index b3ff278..3b35c14 100644
--- a/src/esbuild_plugins/routes.ts
+++ b/src/esbuild_plugins/routes.ts
@@ -24,11 +24,11 @@ export const build_routes = (
"data:application/javascript," + encodeURIComponent(route.text)
) as {
default: {
- render(): SSROutput;
+ render(props: { base_path: string }): SSROutput;
};
};
- const { html, css: _css, head } = module.default.render();
+ const { html, css: _css, head } = module.default.render({ base_path });
const css = _css?.code ?? "";
const dist_path = route.path.replace(".js", ".html");