APIs
JavaScript API
server: (options?: LuathOptions) => Promise
Create a Luath server with custom options. Resolves to an opine
server.
For example:
import { server } from "https://deno.land/x/luath@0.9.1/mod.ts";
import { plugins } from "./plugins.ts";
await server({ root: Deno.cwd(), server: { port: 4000 }, plugins });
build: (options?: LuathOptions) => Promise
Builds the production assets.
For example:
import { build } from "https://deno.land/x/luath@0.9.1/mod.ts";
import { plugins } from "./plugins.ts";
await build({ root: Deno.cwd(), plugins });
Plugin API
Luath makes use of deno-rollup
internally for transpiling and bundling code, utilizing Rollup's well-designed plugin interface for providing features. As a result, any plugin that is compatible with deno-rollup
is also immediately compatible with Luath.
To learn more about Rollup plugins, please refer to the official Rollup documentation.
In addition to the core Rollup plugin APIs, Luath also supports an additional optional hook:
transformIndexHtml?: (html: string) => string
A hook dedicated to transforming the index.html
. It receives the current HTML as a string and should return a transformed HTML string.
For example:
const htmlTitleReplacerPlugin = (title: string) => {
return {
name: 'luath-html-title-replacer-plugin',
transformIndexHtml(html) {
return html.replace(
/<title>(.*?)<\/title>/,
`<title>${title}</title>`,
);
},
};
};
Configuration
When running a Luath application using the CLI, you can provide a configuration file via the --config
flag in the luath serve
command.
Similarly, configuration can also be passed to the Luath JavaScript APIs.
The simplest configuration file just exports an empty object:
// luath.config.ts
export default {};
Conditional configuration can be implemented based on the command
(build
or serve
) by exporting a function:
// luath.config.ts
export default ({ command }: { command: string }) => {
return command === "build"
? { /* ...build specific config... */ }
: { /* ...serve specific config... */ };
};
Available configuration options are:
root?: string
Default: Deno.cwd()
Project root directory for the Luath server.
server?: LuathServerOptions
Default: { port: 4505, hostname: "0.0.0.0" }
Luath server options. Accepts any valid HTTPOptions
or HTTPSOptions
from the Deno http
standard library.
plugins?: LuathPlugin[]
Default: undefined
An array of Luath plugins to use. Please refer to the Plugin API documentation for further details.