API Reference
Classes
Injector
Inject tags into an HTML string.
import { Injector } from "domco/injector";
const injector = new Injector(
`<!doctype html><html><body><!-- comment --></body></html>`,
);
injector
// Set or change the title
.title("My Title")
// pass a TagDescriptor
.head([{ name: "script", attrs: { type: "module", src: "./script.js" } }])
// pass a string of text
.body("Prepended to the body! ", "prepend")
// replace comments
.comment("comment", "My comment")
// stringify HTML
.toString();
Produces the following HTML.
<!doctype html>
<html>
<head>
<title>My Title</title>
<script type="module" src="./script.js"></script>
</head>
<body>
Prepended to the body! My comment
</body>
</html>
Constructors
new Injector()
new Injector(
html
?):Injector
Parameters
• html?: string
The HTML string.
Returns
Default
<!doctype html>
<html>
<head></head>
<body></body>
</html>
Defined in
Methods
body()
body(
tags
,method
):Injector
Inject tags into the body
element.
Parameters
• tags: TagInput
Tags to inject.
• method: InjectMethod
= "append"
Add tags at the end, beginning, or replace. - defaults to "append"
Returns
The Injector instance.
Defined in
comment()
comment(
text
,tags
):Injector
Replace comments with tags.
Parameters
• text: string
Text within comment.
• tags: TagInput
Tags to replace the comment with.
Returns
The Injector instance.
Defined in
head()
head(
tags
,method
):Injector
Inject tags into the head
element.
Parameters
• tags: TagInput
Tags to inject.
• method: InjectMethod
= "append"
Add tags at the end, beginning, or replace. - defaults to "append"
Returns
The Injector instance.
Defined in
title()
title(
text
):Injector
Set or change the document’s title element.
Parameters
• text: string
Text to set or change the title
to.
Returns
The Injector instance.
Defined in
toString()
toString():
string
Returns
string
The HTML.
Defined in
serializeTags()
static
serializeTags(tags
):string
Serializes an array of TagDescriptors into a string.
Parameters
• tags: undefined
| TagInput
Returns
string
Defined in
Type Aliases
Adapter
Adapter:
object
A domco adapter that configures the build to a target production environment.
Type declaration
devMiddleware?
optional
devMiddleware:AdapterMiddleware
[]
Middleware to apply in dev
mode.
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.
noExternal?
optional
noExternal:SSROptions
["noExternal"
]
Passed into Vite config.ssr.noExternal
.
previewMiddleware?
optional
previewMiddleware:AdapterMiddleware
[]
Middleware to apply in preview
mode.
run()?
optional
run: () =>any
The script to run after Vite build is complete.
Returns
any
target?
optional
target:SSRTarget
Passed into Vite config.ssr.target
.
Defined in
AdapterBuilder()<AdapterOptions>
AdapterBuilder<
AdapterOptions
>: (AdapterOptions
?) =>MaybePromise
<Adapter
>
Use this type to create your own adapter. Pass any options for the adapter in as a generic.
Type Parameters
• AdapterOptions = never
Parameters
• AdapterOptions?: AdapterOptions
Returns
Defined in
AdapterEntry()
AdapterEntry: (
AdapterEntryOptions
) =>object
A function that returns an additional entry point to include in the SSR build.
Parameters
• AdapterEntryOptions
• AdapterEntryOptions.funcId: string
The function entry point to import handler
from.
Returns
object
code
code:
string
Code for the entry point.
id
id:
string
The name of the entry point without extension.
Example
"main";
Defined in
AdapterMiddleware
AdapterMiddleware:
Connect.NextHandleFunction
Middleware used in the Vite server for dev and preview.
Defined in
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 func
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
FuncModule
FuncModule:
object
Exports from the SSR +func
entry point.
Type declaration
handler
handler:
Handler
prerender
prerender:
Prerender
Defined in
Handler()
Handler: (
req
) =>MaybePromise
<Response
>
Request handler, takes a web request and returns a web response.
// src/server/+func.ts
import type { Handler } from "domco";
export const handler: Handler = async (req) => {
return new Response("Hello world");
};
Parameters
• req: Request
Returns
MaybePromise
<Response
>
Defined in
InjectMethod
InjectMethod:
"append"
|"prepend"
|"replace"
How to inject tags into the HTML string.
Defined in
MaybePromise<T>
MaybePromise<
T
>:T
|Promise
<T
>
Helper type for a type that could be a promise.
Type Parameters
• T
Defined in
Prerender
Prerender:
string
[] |Set
<string
> | () =>MaybePromise
<string
[] |Set
<string
>>
Paths to prerender at build time.
Example
// src/server/+func.ts
import type { Prerender } from "domco";
export const prerender: Prerender = ["/", "/post-1", "/post-2"];
Defined in
TagDescriptor
TagDescriptor:
object
An object that describes a tag and its children.
Type declaration
attrs?
optional
attrs:Record
<string
,string
|boolean
|undefined
>
The attributes on the tag.
Example
These attributes,
{
class: "text-black",
open: true,
}
would produce the following HTML.
<dialog class="text-black" open>...</dialog>
children?
optional
children:TagInput
Children of the tag. Tags or a string of HTML.
name
name:
string
The tagName of the element.
Example
"h1";
Defined in
TagInput
TagInput:
string
|TagDescriptor
[]
Tags can be a string, or an array of TagDescriptors.
Defined in
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
= {}
Your domco config object.
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()],
});