diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..03b773a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+_fresh/
diff --git a/docs/canary/concepts/ahead-of-time-builds.md b/docs/canary/concepts/ahead-of-time-builds.md
new file mode 100644
index 00000000..e569f067
--- /dev/null
+++ b/docs/canary/concepts/ahead-of-time-builds.md
@@ -0,0 +1,135 @@
+---
+description: |
+ Fresh optimize assets ahead of time, which makes pages load way quicker.
+---
+
+Fresh enables you to pre-optimize frontend assets before the code is deployed.
+During that process the code for Islands will be compressed and optimized, so
+that Fresh can send as little code as possible to the browser. Depending on the
+amount of code an island needs, this process can take several seconds if done on
+the fly serverside.
+
+Doing those optimizations ahead-of-time and deploying the already optimized
+assets alongside with your code, allows Fresh to treat them as like any other
+static file and can serve it immediately without any further processing. On
+pages with islands, having to do no processing greatly speeds up page load
+times.
+
+## Creating an optimized build
+
+To have Fresh optimize all the assets, run one of the following commands:
+
+```sh
+# As a task in newer Fresh projects
+deno task build
+# or invoke it manually
+deno run -A dev.ts build
+```
+
+This will create a `_fresh` folder in the project directory. That folder
+contains the optimized assets and a `snapshot.json` file which includes some
+metadata for Fresh.
+
+> âšī¸ The `_fresh` folder should not be committed to the repository. Add an entry
+> in the `.gitignore` file to ensure that it is not committed. Create that file
+> at the root of your git repository if not present.
+>
+> ```gitignore .gitignore
+> # Ignore fresh build directory
+> _fresh/
+> ```
+
+## Running Fresh with optimized assets
+
+When Fresh is started in non-development mode (usually via `main.ts`), Fresh
+will automatically pick up optimized assets when a `_fresh` folder exists. If
+found, Fresh will print the following message to the terminal:
+
+```sh Terminal output
+Using snapshot found at /path/to/project/_fresh
+```
+
+## Deploying an optimized Fresh project
+
+To generate optimized assets whenever you push changes to the `main` branch of
+your project, copy the following GitHub action and add it under
+`.github/workflows/deploy.yml` in your project.
+
+```yml .github/workflows/deploy.yml
+name: Deploy
+on:
+ push:
+ branches: [main]
+ pull_request:
+ branches: main
+
+jobs:
+ deploy:
+ name: Deploy
+ runs-on: ubuntu-latest
+
+ permissions:
+ id-token: write # Needed for auth with Deno Deploy
+ contents: read # Needed to clone the repository
+
+ steps:
+ - name: Clone repository
+ uses: actions/checkout@v3
+
+ - name: Install Deno
+ uses: denoland/setup-deno@v1
+ with:
+ deno-version: v1.x
+
+ - name: Build step
+ run: "deno task build" # đ Update the build command(s) if necessary
+
+ - name: Upload to Deno Deploy
+ uses: denoland/deployctl@v1
+ with:
+ project: "example-project" # đ Update the deploy project name if necessary
+ entrypoint: "./main.ts" # đ Update the entrypoint if necessary
+```
+
+> âšī¸ **Important:** The project name here must match the project name you've
+> picked in Deno Deploy.
+
+On the Deno Deploy side change the GitHub integration mode to GitHub Actions.
+You need to unlink first, if you have an existing project that's linked with the
+"Automatic" mode.
+
+
+
+Once this is set up you're ready for your next deployment. Whenever a new PR is
+merged into the `main` branch on GitHub the deploy action will be executed and
+deploy the optimized assets to Deno Deploy.
+
+## Migrating existing projects with Plugins
+
+If you're using Fresh plugins, extract them into a `fresh.config.ts` file, so
+that both the `dev.ts` and `main.ts` script have access to them.
+
+```ts fresh.config.ts
+import { defineConfig } from "$fresh/server.ts";
+import twindPlugin from "$fresh/plugins/twind.ts";
+import twindConfig from "./twind.config.ts";
+
+export default defineConfig({
+ plugins: [twindPlugin(twindConfig)],
+});
+```
+
+```ts main.ts
+import { start } from "$fresh/server.ts";
+import manifest from "./fresh.gen.ts";
+import config from "./fresh.config.ts";
+
+await start(manifest, config);
+```
+
+```ts dev.ts
+import dev from "$fresh/dev.ts";
+import config from "./fresh.config.ts";
+
+await dev(import.meta.url, "./main.ts", config);
+```
diff --git a/docs/toc.ts b/docs/toc.ts
index 7db10e66..d261f37d 100644
--- a/docs/toc.ts
+++ b/docs/toc.ts
@@ -56,6 +56,7 @@ const toc: RawTableOfContents = {
["middleware", "Middlewares", "link:canary"],
["error-pages", "Error pages", "link:latest"],
["data-fetching", "Data fetching", "link:latest"],
+ ["ahead-of-time-builds", "Ahead-of-time Builds", "link:canary"],
["deployment", "Deployment", "link:latest"],
["plugins", "Plugins", "link:latest"],
["updating", "Updating Fresh", "link:latest"],
diff --git a/init.ts b/init.ts
index beeb3399..1beb228d 100644
--- a/init.ts
+++ b/init.ts
@@ -105,6 +105,9 @@ const GITIGNORE = `# dotenv environment variable files
.env.test.local
.env.production.local
.env.local
+
+# Fresh build directory
+_fresh/
`;
await Deno.writeTextFile(
@@ -498,6 +501,20 @@ try {
// Skip this and be silent if there is a network issue.
}
+let FRESH_CONFIG_TS = `import { defineConfig } from "$fresh/server.ts";\n`;
+if (useTwind) {
+ FRESH_CONFIG_TS += `import twindPlugin from "$fresh/plugins/twind.ts"
+import twindConfig from "./twind.config.ts";`;
+}
+
+FRESH_CONFIG_TS += `
+export default defineConfig({${
+ useTwind ? `\n plugins: [twindPlugin(twindConfig)]\n` : ""
+}});
+`;
+const CONFIG_TS_PATH = join(resolvedDirectory, "fresh.config.ts");
+await Deno.writeTextFile(CONFIG_TS_PATH, FRESH_CONFIG_TS);
+
let MAIN_TS = `///
///
///
@@ -508,27 +525,20 @@ import "$std/dotenv/load.ts";
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
+import config from "./fresh.config.ts";
`;
-if (useTwind) {
- MAIN_TS += `
-import twindPlugin from "$fresh/plugins/twind.ts";
-import twindConfig from "./twind.config.ts";
-`;
-}
-
MAIN_TS += `
-await start(manifest${
- useTwind ? ", { plugins: [twindPlugin(twindConfig)] }" : ""
-});\n`;
+await start(manifest, config);\n`;
const MAIN_TS_PATH = join(resolvedDirectory, "main.ts");
await Deno.writeTextFile(MAIN_TS_PATH, MAIN_TS);
const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/
import dev from "$fresh/dev.ts";
+import config from "./fresh.config.ts";
-await dev(import.meta.url, "./main.ts");
+await dev(import.meta.url, "./main.ts", config);
`;
const DEV_TS_PATH = join(resolvedDirectory, "dev.ts");
await Deno.writeTextFile(DEV_TS_PATH, DEV_TS);
@@ -544,6 +554,8 @@ const config = {
check:
"deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
start: "deno run -A --watch=static/,routes/ dev.ts",
+ build: "deno run -A dev.ts build",
+ preview: "deno run -A main.ts",
update: "deno run -A -r https://fresh.deno.dev/update .",
},
lint: {
diff --git a/src/build/esbuild.ts b/src/build/esbuild.ts
index fa7b0d65..66bbad17 100644
--- a/src/build/esbuild.ts
+++ b/src/build/esbuild.ts
@@ -163,7 +163,7 @@ export class EsbuildSnapshot implements BuildSnapshot {
}
get paths(): string[] {
- return Object.keys(this.#files);
+ return Array.from(this.#files.keys());
}
read(path: string): Uint8Array | null {
diff --git a/src/dev/build.ts b/src/dev/build.ts
new file mode 100644
index 00000000..24cd639c
--- /dev/null
+++ b/src/dev/build.ts
@@ -0,0 +1,43 @@
+import { ServerContext } from "../server/context.ts";
+import { FreshOptions, Manifest } from "../server/mod.ts";
+import { dirname, fromFileUrl, join, toFileUrl } from "../server/deps.ts";
+import { fs } from "./deps.ts";
+
+export async function build(
+ manifestPath: string,
+ opts: FreshOptions,
+) {
+ const manifest = (await import(toFileUrl(manifestPath).href))
+ .default as Manifest;
+
+ const outDir = join(dirname(fromFileUrl(manifest.baseUrl)), "_fresh");
+
+ // Ensure that build dir is empty
+ await fs.emptyDir(outDir);
+
+ const ctx = await ServerContext.fromManifest(manifest, {
+ ...opts,
+ skipSnapshot: false,
+ });
+
+ // Bundle assets
+ const snapshot = await ctx.buildSnapshot();
+
+ // Write output files to disk
+ await Promise.all(snapshot.paths.map((fileName) => {
+ const data = snapshot.read(fileName);
+ if (data === null) return;
+
+ return Deno.writeFile(join(outDir, fileName), data);
+ }));
+
+ // Write dependency snapshot file to disk
+ const deps: Record = {};
+ for (const filePath of snapshot.paths) {
+ const dependencies = snapshot.dependencies(filePath);
+ deps[filePath] = dependencies;
+ }
+
+ const snapshotPath = join(outDir, "snapshot.json");
+ await Deno.writeTextFile(snapshotPath, JSON.stringify(deps, null, 2));
+}
diff --git a/src/dev/deps.ts b/src/dev/deps.ts
index 13e989ed..6ac6533f 100644
--- a/src/dev/deps.ts
+++ b/src/dev/deps.ts
@@ -23,6 +23,7 @@ export { gte } from "https://deno.land/std@0.193.0/semver/mod.ts";
export { existsSync } from "https://deno.land/std@0.193.0/fs/mod.ts";
export * as semver from "https://deno.land/std@0.195.0/semver/mod.ts";
export * as JSONC from "https://deno.land/std@0.195.0/jsonc/mod.ts";
+export * as fs from "https://deno.land/std@0.195.0/fs/mod.ts";
// ts-morph
export { Node, Project } from "https://deno.land/x/ts_morph@17.0.1/mod.ts";
diff --git a/src/dev/mod.ts b/src/dev/mod.ts
index 5ef0e653..519e803d 100644
--- a/src/dev/mod.ts
+++ b/src/dev/mod.ts
@@ -11,6 +11,8 @@ import {
WalkEntry,
} from "./deps.ts";
import { error } from "./error.ts";
+import { FreshOptions } from "../server/mod.ts";
+import { build } from "./build.ts";
const MIN_DENO_VERSION = "1.31.0";
@@ -183,7 +185,11 @@ export default manifest;
);
}
-export async function dev(base: string, entrypoint: string) {
+export async function dev(
+ base: string,
+ entrypoint: string,
+ options: FreshOptions = {},
+) {
ensureMinDenoVersion();
// Run update check in background
@@ -209,7 +215,11 @@ export async function dev(base: string, entrypoint: string) {
if (manifestChanged) await generate(dir, newManifest);
- await import(entrypoint);
+ if (Deno.args.includes("build")) {
+ await build(join(dir, "fresh.gen.ts"), options);
+ } else {
+ await import(entrypoint);
+ }
}
function arraysEqual(a: T[], b: T[]): boolean {
diff --git a/src/server/context.ts b/src/server/context.ts
index b8eff35f..9eb5b919 100644
--- a/src/server/context.ts
+++ b/src/server/context.ts
@@ -1,4 +1,5 @@
import {
+ colors,
dirname,
extname,
fromFileUrl,
@@ -51,6 +52,7 @@ import {
Builder,
BuildSnapshot,
EsbuildBuilder,
+ EsbuildSnapshot,
JSXConfig,
} from "../build/mod.ts";
import { InternalRoute } from "./router.ts";
@@ -117,6 +119,7 @@ export class ServerContext {
jsxConfig: JSXConfig,
dev: boolean = isDevMode(),
routerOptions: RouterOptions,
+ snapshot: BuildSnapshot | null = null,
) {
this.#routes = routes;
this.#islands = islands;
@@ -129,7 +132,7 @@ export class ServerContext {
this.#error = error;
this.#plugins = plugins;
this.#dev = dev;
- this.#builder = new EsbuildBuilder({
+ this.#builder = snapshot ?? new EsbuildBuilder({
buildID: BUILD_ID,
entrypoints: collectEntrypoints(this.#dev, this.#islands, this.#plugins),
configPath,
@@ -144,7 +147,7 @@ export class ServerContext {
*/
static async fromManifest(
manifest: Manifest,
- opts: FreshOptions,
+ opts: FreshOptions & { skipSnapshot?: boolean },
): Promise {
// Get the manifest' base URL.
const baseUrl = new URL("./", manifest.baseUrl).href;
@@ -158,6 +161,40 @@ export class ServerContext {
);
}
+ // Restore snapshot if available
+ let snapshot: BuildSnapshot | null = null;
+ // Load from snapshot if not explicitly requested not to
+ const loadFromSnapshot = !opts.skipSnapshot;
+ if (loadFromSnapshot) {
+ const snapshotDirPath = join(dirname(configPath), "_fresh");
+ try {
+ if ((await Deno.stat(snapshotDirPath)).isDirectory) {
+ console.log(
+ `Using snapshot found at ${colors.cyan(snapshotDirPath)}`,
+ );
+
+ const snapshotPath = join(snapshotDirPath, "snapshot.json");
+ const json = JSON.parse(await Deno.readTextFile(snapshotPath));
+ const dependencies = new Map(
+ Object.entries(json),
+ );
+
+ const files = new Map();
+ const names = Object.keys(json);
+ await Promise.all(names.map(async (name) => {
+ const filePath = join(snapshotDirPath, name);
+ files.set(name, await Deno.readFile(filePath));
+ }));
+
+ snapshot = new EsbuildSnapshot(files, dependencies);
+ }
+ } catch (err) {
+ if (!(err instanceof Deno.errors.NotFound)) {
+ throw err;
+ }
+ }
+ }
+
config.compilerOptions ??= {};
let jsx: "react" | "react-jsx";
@@ -415,6 +452,7 @@ export class ServerContext {
jsxConfig,
dev,
opts.router ?? DEFAULT_ROUTER_OPTIONS,
+ snapshot,
);
}
@@ -474,7 +512,7 @@ export class ServerContext {
return this.#builder;
}
- async #buildSnapshot() {
+ async buildSnapshot() {
if ("build" in this.#builder) {
const builder = this.#builder;
this.#builder = builder.build();
@@ -950,7 +988,7 @@ export class ServerContext {
*/
#bundleAssetRoute = (): router.MatchHandler => {
return async (_req, _ctx, params) => {
- const snapshot = await this.#buildSnapshot();
+ const snapshot = await this.buildSnapshot();
const contents = snapshot.read(params.path);
if (!contents) return new Response(null, { status: 404 });
diff --git a/src/server/defines.ts b/src/server/defines.ts
index 04b53f43..b396ffd7 100644
--- a/src/server/defines.ts
+++ b/src/server/defines.ts
@@ -4,10 +4,15 @@ import {
AsyncRoute,
LayoutContext,
RouteContext,
+ StartOptions,
} from "./types.ts";
import { checkAsyncComponent } from "./render.ts";
import { AppContext } from "$fresh/server.ts";
+export function defineConfig(config: StartOptions): StartOptions {
+ return config;
+}
+
// Route creation helpers
export function defineRoute<
T,
diff --git a/src/server/mod.ts b/src/server/mod.ts
index 828aa288..5f2d6985 100644
--- a/src/server/mod.ts
+++ b/src/server/mod.ts
@@ -15,7 +15,12 @@ import {
StartOptions,
UnknownHandler,
} from "./types.ts";
-export { defineApp, defineLayout, defineRoute } from "./defines.ts";
+export {
+ defineApp,
+ defineConfig,
+ defineLayout,
+ defineRoute,
+} from "./defines.ts";
export type {
AppContext,
AppProps,
@@ -78,6 +83,7 @@ export interface Manifest {
export interface DenoConfig {
imports?: Record;
importMap?: string;
+ tasks?: Record;
compilerOptions?: {
jsx?: string;
jsxImportSource?: string;
diff --git a/tests/build_test.ts b/tests/build_test.ts
new file mode 100644
index 00000000..231700af
--- /dev/null
+++ b/tests/build_test.ts
@@ -0,0 +1,87 @@
+import * as path from "$std/path/mod.ts";
+import { puppeteer } from "./deps.ts";
+import { assert } from "$std/_util/asserts.ts";
+import { startFreshServer, waitForText } from "$fresh/tests/test_utils.ts";
+
+Deno.test("build snapshot and restore from it", async (t) => {
+ const fixture = path.join(Deno.cwd(), "tests", "fixture_build");
+ const outDir = path.join(fixture, "_fresh");
+
+ try {
+ await t.step("build snapshot", async () => {
+ await new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "-A",
+ path.join(fixture, "dev.ts"),
+ "build",
+ ],
+ stdin: "null",
+ stdout: "inherit",
+ stderr: "inherit",
+ }).output();
+
+ assert((await Deno.stat(outDir)).isDirectory, "Missing output directory");
+ });
+
+ await t.step("check snapshot file", async () => {
+ const snapshot = JSON.parse(
+ await Deno.readTextFile(path.join(outDir, "snapshot.json")),
+ );
+ assert(
+ Array.isArray(snapshot["island-counter_default.js"]),
+ "Island output file not found in snapshot",
+ );
+ assert(
+ Array.isArray(snapshot["main.js"]),
+ "main.js output file not found in snapshot",
+ );
+ assert(
+ Array.isArray(snapshot["signals.js"]),
+ "signals.js output file not found in snapshot",
+ );
+ assert(
+ Array.isArray(snapshot["deserializer.js"]),
+ "deserializer.js output file not found in snapshot",
+ );
+ });
+
+ await t.step("restore from snapshot", async () => {
+ const { lines, serverProcess, address, output } = await startFreshServer({
+ args: [
+ "run",
+ "-A",
+ path.join(fixture, "./main.ts"),
+ ],
+ });
+
+ // Check if restore snapshot message was printed
+ assert(
+ output.find((line) => line.includes("Using snapshot found at")),
+ "Did not print restoring from snapshot line",
+ );
+
+ try {
+ const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
+
+ try {
+ const page = await browser.newPage();
+ await page.goto(address);
+
+ await page.waitForSelector("button:not([disabled])");
+ await page.click("button");
+
+ await waitForText(page, "p", "1");
+ } finally {
+ await browser.close();
+ }
+ } finally {
+ await lines.cancel();
+ serverProcess.kill("SIGTERM");
+ await serverProcess.status;
+ }
+ });
+ } finally {
+ await Deno.remove(path.join(fixture, "_fresh"), { recursive: true });
+ }
+});
diff --git a/tests/cli_test.ts b/tests/cli_test.ts
index 761ff709..a3471dd3 100644
--- a/tests/cli_test.ts
+++ b/tests/cli_test.ts
@@ -1,5 +1,6 @@
import * as path from "$std/path/mod.ts";
-import { Status } from "../src/server/deps.ts";
+import { DenoConfig } from "$fresh/server.ts";
+import { JSONC, Status } from "../src/server/deps.ts";
import {
assert,
assertEquals,
@@ -49,6 +50,8 @@ Deno.test({
const files = [
`/README.md`,
+ `/.gitignore`,
+ `/deno.json`,
`/fresh.gen.ts`,
`/components/Button.tsx`,
`/islands/Counter.tsx`,
@@ -79,6 +82,15 @@ Deno.test({
assertEquals(code, 0);
});
+ await t.step("check deno.json", async () => {
+ const configPath = path.join(tmpDirName, "deno.json");
+ const json = JSON.parse(await Deno.readTextFile(configPath));
+
+ assert(json.tasks.start, "Missing 'start' task");
+ assert(json.tasks.build, "Missing 'build' task");
+ assert(json.tasks.preview, "Missing 'preview' task");
+ });
+
await t.step("start up the server and access the root page", async () => {
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "--check", "main.ts"],
@@ -371,10 +383,20 @@ Deno.test("fresh-update", async function fn(t) {
);
});
+ await t.step("check deno.json", async () => {
+ const configPath = path.join(tmpDirName, "deno.json");
+ const json = JSONC.parse(await Deno.readTextFile(configPath)) as DenoConfig;
+
+ assert(json.tasks?.start, "Missing 'start' task");
+ assert(json.tasks?.build, "Missing 'build' task");
+ assert(json.tasks?.preview, "Missing 'preview' task");
+ });
+
const comment = "// This is a test comment";
const regex = /("preact": "https:\/\/esm.sh\/preact@[\d.]+",\n)/;
const originalName = `${tmpDirName}/deno.json`;
const updatedName = `${originalName}c`;
+
await t.step("execute update command deno.jsonc support", async () => {
try {
Deno.renameSync(originalName, updatedName);
diff --git a/tests/deps.ts b/tests/deps.ts
index daa5faec..acfe0d3b 100644
--- a/tests/deps.ts
+++ b/tests/deps.ts
@@ -29,3 +29,4 @@ export {
} from "https://esm.sh/linkedom@0.15.1";
export { defineConfig, type Preset } from "https://esm.sh/@twind/core@1.1.3";
export { default as presetTailwind } from "https://esm.sh/@twind/preset-tailwind@1.1.4";
+export * as fs from "https://deno.land/std@0.195.0/fs/mod.ts";
diff --git a/tests/fixture_build/deno.json b/tests/fixture_build/deno.json
new file mode 100644
index 00000000..9d782057
--- /dev/null
+++ b/tests/fixture_build/deno.json
@@ -0,0 +1,15 @@
+{
+ "lock": false,
+ "imports": {
+ "$fresh/": "../../",
+ "preact": "https://esm.sh/preact@10.15.1",
+ "preact/": "https://esm.sh/preact@10.15.1/",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
+ "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
+ "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
+ },
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact"
+ }
+}
diff --git a/tests/fixture_build/dev.ts b/tests/fixture_build/dev.ts
new file mode 100755
index 00000000..2d85d6c1
--- /dev/null
+++ b/tests/fixture_build/dev.ts
@@ -0,0 +1,5 @@
+#!/usr/bin/env -S deno run -A --watch=static/,routes/
+
+import dev from "$fresh/dev.ts";
+
+await dev(import.meta.url, "./main.ts");
diff --git a/tests/fixture_build/fresh.gen.ts b/tests/fixture_build/fresh.gen.ts
new file mode 100644
index 00000000..fa16c42d
--- /dev/null
+++ b/tests/fixture_build/fresh.gen.ts
@@ -0,0 +1,18 @@
+// DO NOT EDIT. This file is generated by Fresh.
+// This file SHOULD be checked into source version control.
+// This file is automatically updated during development when running `dev.ts`.
+
+import * as $0 from "./routes/index.tsx";
+import * as $$0 from "./islands/Counter.tsx";
+
+const manifest = {
+ routes: {
+ "./routes/index.tsx": $0,
+ },
+ islands: {
+ "./islands/Counter.tsx": $$0,
+ },
+ baseUrl: import.meta.url,
+};
+
+export default manifest;
diff --git a/tests/fixture_build/islands/Counter.tsx b/tests/fixture_build/islands/Counter.tsx
new file mode 100644
index 00000000..5f015b1e
--- /dev/null
+++ b/tests/fixture_build/islands/Counter.tsx
@@ -0,0 +1,22 @@
+import type { Signal } from "@preact/signals";
+import { IS_BROWSER } from "$fresh/runtime.ts";
+
+interface CounterProps {
+ count: Signal;
+ id: string;
+}
+
+export default function Counter(props: CounterProps) {
+ return (
+
+
{props.count}
+
+
+ );
+}
diff --git a/tests/fixture_build/main.ts b/tests/fixture_build/main.ts
new file mode 100644
index 00000000..bb97cc80
--- /dev/null
+++ b/tests/fixture_build/main.ts
@@ -0,0 +1,10 @@
+///
+///
+///
+///
+///
+
+import { start } from "$fresh/server.ts";
+import routes from "./fresh.gen.ts";
+
+await start(routes);
diff --git a/tests/fixture_build/routes/index.tsx b/tests/fixture_build/routes/index.tsx
new file mode 100644
index 00000000..36fc6506
--- /dev/null
+++ b/tests/fixture_build/routes/index.tsx
@@ -0,0 +1,11 @@
+import { useSignal } from "@preact/signals";
+import Counter from "../islands/Counter.tsx";
+
+export default function Home() {
+ const signal = useSignal(0);
+ return (
+
+
+
+ );
+}
diff --git a/tests/test_utils.ts b/tests/test_utils.ts
index d6f67ee3..40dd446a 100644
--- a/tests/test_utils.ts
+++ b/tests/test_utils.ts
@@ -15,13 +15,13 @@ export function parseHtml(input: string) {
}
export async function startFreshServer(options: Deno.CommandOptions) {
- const { serverProcess, lines, address } = await spawnServer(options);
+ const { serverProcess, lines, address, output } = await spawnServer(options);
if (!address) {
throw new Error("Server didn't start up");
}
- return { serverProcess, lines, address };
+ return { serverProcess, lines, address, output };
}
export async function fetchHtml(url: string) {
@@ -259,8 +259,10 @@ async function spawnServer(
preventCancel: true,
});
+ const output: string[] = [];
let address = "";
for await (const line of lines) {
+ output.push(line);
const match = line.match(/https?:\/\/localhost:\d+/g);
if (match) {
address = match[0];
@@ -268,5 +270,5 @@ async function spawnServer(
}
}
- return { serverProcess, lines, address };
+ return { serverProcess, lines, address, output };
}
diff --git a/update.ts b/update.ts
index 5436c4a8..bd6dc306 100644
--- a/update.ts
+++ b/update.ts
@@ -88,6 +88,16 @@ if (!denoJson.lint.rules.tags.includes("recommended")) {
denoJson.lint.rules.tags.push("recommended");
}
+if (!denoJson.tasks) {
+ denoJson.tasks = {};
+}
+if (!denoJson.tasks.build) {
+ denoJson.tasks.build = "deno run -A dev.ts build";
+}
+if (!denoJson.tasks.preview) {
+ denoJson.tasks.preview = "deno run -A main.ts";
+}
+
freshImports(denoJson.imports);
if (denoJson.imports["twind"]) {
twindImports(denoJson.imports);
diff --git a/www/deno.json b/www/deno.json
index dcb92cd4..42dd6070 100644
--- a/www/deno.json
+++ b/www/deno.json
@@ -1,7 +1,9 @@
{
"lock": false,
"tasks": {
- "start": "deno run -A --watch=static/,routes/ dev.ts"
+ "start": "deno run -A --watch=static/,routes/ dev.ts",
+ "build": "deno run -A dev.ts build",
+ "preview": "deno run -A main.ts"
},
"imports": {
"$fresh/": "../",
diff --git a/www/dev.ts b/www/dev.ts
index 2d85d6c1..1fe3e340 100755
--- a/www/dev.ts
+++ b/www/dev.ts
@@ -1,5 +1,6 @@
#!/usr/bin/env -S deno run -A --watch=static/,routes/
import dev from "$fresh/dev.ts";
+import config from "./fresh.config.ts";
-await dev(import.meta.url, "./main.ts");
+await dev(import.meta.url, "./main.ts", config);
diff --git a/www/fresh.config.ts b/www/fresh.config.ts
new file mode 100644
index 00000000..4b076dd4
--- /dev/null
+++ b/www/fresh.config.ts
@@ -0,0 +1,7 @@
+import twindPlugin from "$fresh/plugins/twind.ts";
+import twindConfig from "./twind.config.ts";
+import { defineConfig } from "$fresh/server.ts";
+
+export default defineConfig({
+ plugins: [twindPlugin(twindConfig)],
+});
diff --git a/www/main.ts b/www/main.ts
index 82234c72..36b221d6 100644
--- a/www/main.ts
+++ b/www/main.ts
@@ -5,9 +5,8 @@
///
import { start } from "$fresh/server.ts";
-import twindPlugin from "$fresh/plugins/twind.ts";
import manifest from "./fresh.gen.ts";
-import twindConfig from "./twind.config.ts";
+import config from "./fresh.config.ts";
-await start(manifest, { plugins: [twindPlugin(twindConfig)] });
+await start(manifest, config);
diff --git a/www/routes/gfm.css.ts b/www/routes/gfm.css.ts
index b6c34847..18555fa6 100644
--- a/www/routes/gfm.css.ts
+++ b/www/routes/gfm.css.ts
@@ -77,6 +77,13 @@ ol.nested li:before {
font-size: .8125rem;
line-height: 1;
}
+
+.highlight-source-yml .atrule {
+ color: var(--color-prettylights-syntax-entity);
+}
+.highlight-source-yml .string {
+ color: var(--color-prettylights-syntax-string);
+}
`;
export const handler: Handlers = {
diff --git a/www/static/docs/deno-deploy-gh-action.jpg b/www/static/docs/deno-deploy-gh-action.jpg
new file mode 100644
index 00000000..48c5fd54
Binary files /dev/null and b/www/static/docs/deno-deploy-gh-action.jpg differ
diff --git a/www/utils/markdown.ts b/www/utils/markdown.ts
index 8ba79532..215b239f 100644
--- a/www/utils/markdown.ts
+++ b/www/utils/markdown.ts
@@ -5,6 +5,7 @@ import "https://esm.sh/prismjs@1.29.0/components/prism-tsx.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-diff.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-json.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-bash.js?no-check";
+import "https://esm.sh/prismjs@1.29.0/components/prism-yaml.js?no-check";
export { extract as frontMatter } from "$std/front_matter/yaml.ts";