domco

API Reference

Type Aliases

Adapter

Adapter: object

Type declaration

devMiddleware?

optional devMiddleware: CreateAppOptions["middleware"]

Middleware to apply in dev mode. For production middleware, export it from the adapter module, and then import into the entry point.

entry

entry: AdapterEntry

Entry point for the server application.

message

message: string

Message to log when the build is complete.

name

name: string

The name of the adapter.

previewMiddleware?

optional previewMiddleware: CreateAppOptions["middleware"]

Middleware to apply in preview mode. For production middleware, export it from the adapter module, and then import into the entry point.

run()?

optional run: () => any

The script to run after Vite build is complete.

Returns

any

ssrTarget

ssrTarget: SSRTarget

Target for SSR build.

Defined in

types/public/index.ts:44


AdapterBuilder()<AdapterOptions>

AdapterBuilder<AdapterOptions>: (AdapterOptions?) => MaybePromise<Adapter>

Type Parameters

AdapterOptions = object

Parameters

AdapterOptions?: AdapterOptions

Returns

MaybePromise<Adapter>

Defined in

types/public/index.ts:83


AdapterEntry()

AdapterEntry: (AdapterEntryOptions) => object

Parameters

AdapterEntryOptions

AdapterEntryOptions.appId: string

The app entrypoint to import createApp from.

Returns

object

code

code: string

Code for the entrypoint.

id

id: string

The name of the entrypoint without extension.

Example
"main";

Defined in

types/public/index.ts:29


Client()

Client: (routePath?) => HtmlEscapedString

Parameters

routePath?: string

Returns

HtmlEscapedString

Defined in

types/public/index.ts:146


CreateAppMiddleware

CreateAppMiddleware: object

Type declaration

handler

handler: MiddlewareHandler

The middleware to apply.

path

path: string

Path to apply the middleware to.

Defined in

types/public/index.ts:7


CreateAppOptions

CreateAppOptions: object

Type declaration

devServer?

optional devServer: ViteDevServer

Only used in dev to call the server.

honoOptions?

optional honoOptions: HonoOptions<Env>

Passthrough options to the Hono app.

middleware?

optional middleware: CreateAppMiddleware[]

Middleware to be applied before any routes. Useful for adapters that need to inject middleware.

Defined in

types/public/index.ts:15


DomcoConfig

DomcoConfig: object

domco Config

Use if you want to create a separate object for your domco config. Pass the config into the domco vite plugin.

Type declaration

adapter?

optional adapter: ReturnType<AdapterBuilder>

domco adapter.

Defaults to undefined - creates a app build only.

Default
undefined;
Example
import { adapter } from `"domco/adapter/...";`

Example

// vite.config.ts
import { domco, type DomcoConfig } from "domco";
import { defineConfig } from "vite";

const config: DomcoConfig = {
	// options...
};

export default defineConfig({
	plugins: [domco(config)],
});

Defined in

types/public/index.ts:109


DomcoContextVariableMap

DomcoContextVariableMap: object

Extend Hono’s variable map with domco’s.

Hono reference

Type declaration

client

client: Client

The script tags for any +client.(js,ts,jsx,tsx) within src can be accessed through the client context variable. This is useful if you are wanting to include a client side script but are not using a page file for your HTML, since the names of these tags will be different after your client application has been built.

For example, if you are using JSX to render the markup for your application you can utilize the client variable to include client side scripts.

Also, the link tags for any css imported into the script will be included.

In development, the tags will link directly to the script.

In production, domco will read dist/client/.vite/manifest.json and use the hashed file names generated from the build.

Param

If routePath is left undefined, the current route’s ./+client.(js,ts,jsx,tsx) will be returned. Otherwise, you can use an alternative routePath to get a different route’s tags.

Example
// HTML example
// src/.../+server.(js,ts,jsx,tsx)

import { Hono } from "hono";
import { html } from "hono/html";

const app = new Hono();

app.get("/", (c) => {
	// gets `./+client.(js,ts,jsx,tsx)`
	const tags = c.var.client();

	// gets `src/route/path/+client.(js,ts,jsx,tsx)`
	const differentTags = c.var.client("/route/path")

	return c.html(html`
		${tags}
		<p>Partial with client side script</p>
	`);
});

export default app;

// JSX example

app.get("/", (c) => {
	return c.html(
		<>
			{c.var.client()}
			<p>Partial with client side script</p>
		</>
	`);
});

page

page: Page

Any +page.html within src can be accessed through the page context variable. This provides the HTML after processing by Vite.

Param

If routePath is left undefined, the current route’s ./+page.html will be returned. Otherwise, you can use an alternative routePath to get a different page.

Example
// src/.../+server.(js,ts,jsx,tsx)
import { Hono } from "hono";

app.get("/", (c) => {
	// gets `./+page.html`
	const page = c.var.page();

	// gets `src/route/path/+page.html`
	const differentPage = c.var.page("/route/path");

	return c.html(page);
});

export default app;

server

server: Server

fetch with the origin set, pass in the local path instead of the entire url.

Param

the local path to request

Param

RequestInit

Example
// src/.../+server.(js,ts,jsx,tsx)
import { Hono } from "hono";

const app = new Hono();

app.get("/", (c) => {
	// dev: fetch("http://localhost:5173/route/path")
	// prod: fetch("https://example.com/route/path")
	const res = await c.var.server("/route/path")

	// ...
});

export default app;

Example

// src/global.d.ts
/// <reference types="vite/client" />
import type { DomcoContextVariableMap } from "domco";
import "hono";

declare module "hono" {
	interface ContextVariableMap extends DomcoContextVariableMap {}
}

Defined in

types/public/index.ts:171


Page()

Page: (routePath?) => string

Parameters

routePath?: string

Returns

string

Defined in

types/public/index.ts:144


Prerender

Prerender: string[] | true

Paths to prerender relative to the current route.

Example

// src/posts/+server.ts
import type { Prerender } from "domco";

// prerender current route
export const prerender: Prerender = true;

// prerender multiple paths relative to the current route.
export const prerender: Prerender = ["/", "/post-1", "/post-2"];

Defined in

types/public/index.ts:142


Server()

Server: (pathname, init?) => MaybePromise<Response>

Parameters

pathname: string

init?: RequestInit

Returns

MaybePromise<Response>

Defined in

types/public/index.ts:148

Functions

domco()

domco(domcoConfig): Promise<Plugin<any>[]>

Creates domco Vite plugin, add to your plugins array within your vite.config to start using domco.

Parameters

domcoConfig: DomcoConfig = {}

Returns

Promise<Plugin<any>[]>

The domco Vite plugin.

Example

// vite.config.ts
import { domco } from "domco";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: [domco()],
});

Defined in

plugin/index.ts:31

Edit this page