loadMeekoConfig
Loads and validates a project's meeko.config.ts (or .mts, .js, .mjs) with Node 24 and returns its configuration, or {} if absent.
import { loadMeekoConfig } from "@meekojs/meeko/build";loadMeekoConfig imports a project's configuration like meeko dev, meeko check and meeko build: it looks for meeko.config.ts, .mts, .js or .mjs in the folder, imports it using Node 24's TypeScript support (without compiling or bundling) and validates fields Meeko knows. It returns the default export, or {} if the project has no configuration.
Use it for tools that need to read project configuration: a deployment script checking server.adapter, a generator reading site, a test.
Usage#
import { loadMeekoConfig } from "@meekojs/meeko/build";
const config = await loadMeekoConfig(process.cwd());
const adapter = config.server?.adapter ?? "node";
console.log(`adapter: ${adapter}, site: ${config.site ?? "(no site)"}`);Type#
function loadMeekoConfig(projectRoot: string): Promise<MeekoConfig>interface MeekoConfig {
readonly viewTransitions?: boolean
readonly components?: {
readonly dirs?: readonly {
readonly path: string
readonly prefix?: string
}[]
}
readonly layers?: readonly string[]
readonly extends?: readonly string[]
readonly modules?: readonly MeekoModuleEntry[]
readonly imports?: {
readonly appDirs?: readonly string[]
readonly sharedDirs?: readonly string[]
readonly serverDirs?: readonly string[]
}
readonly alias?: Readonly<Record<string, string | false>>
readonly server?: MeekoServerConfig
readonly css?: { readonly scopeAttribute?: 'all' | 'matched' }
readonly document?: DocumentConfig
readonly dev?: {
readonly serverLogs?: boolean
}
readonly devtools?: boolean | MeekoDevtoolsConfig
readonly site?: string
readonly sitemap?: boolean | SitemapConfig
readonly robots?: boolean | RobotsConfig
readonly theme?: boolean | ThemeConfig
}Parameters#
| Parameter | Type | Default | Description |
|---|---|---|---|
projectRoot |
path | required | Project folder containing meeko.config.*. |
Return value#
A promise of MeekoConfig: the default-exported object unchanged (with or without defineMeekoConfig). It does not resolve modules or layers, apply defaults or execute module setup functions: it returns what you wrote.
| Case | Result |
|---|---|
| No configuration file | {} |
| One valid file | The default export. |
Multiple files (meeko.config.ts and .mjs) |
Rejects with Error: Hay varios archivos de configuración de Meeko: … |
| A field with an invalid value | Rejects with TypeError: <archivo>: server.adapter debe ser "node", "cloudflare", "deno", "bun" o "static" and similar errors. |
| The file cannot be imported | Rejects with Error: No se puede cargar <archivo>: <error de Node>, with the original in cause. |
A key read by neither Meeko nor a module (since 1.7) |
Warns on standard error and returns it unchanged: [meeko] Aviso: meeko.config.ts tiene la clave desconocida "sitmap", que Meeko ignora. ¿Quisiste decir "sitemap"?. |
| The default export is not an object | Rejects with TypeError: <archivo> debe exportar por defecto un objeto de configuración de Meeko. |
Examples#
A deployment script that chooses the target#
import { loadMeekoConfig } from "@meekojs/meeko/build";
const config = await loadMeekoConfig(process.cwd());
switch (config.server?.adapter ?? "node") {
case "cloudflare": console.log("npx wrangler deploy --config .meeko/output/cloudflare/wrangler.jsonc"); break;
case "static": console.log("rsync -a .meeko/output/static/ servidor:/srv/www/"); break;
default: console.log("docker build -t tienda .");
}Check configuration in a test#
import { test } from "node:test";
import assert from "node:assert/strict";
import { loadMeekoConfig } from "@meekojs/meeko/build";
test("production declares the public site", async () => {
const config = await loadMeekoConfig(process.cwd());
assert.match(String(config.site), /^https:\/\//);
});Common mistakes#
An invalid value#
// meeko.config.ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ server: { adapter: "node", port: "8080" } });TypeError: C:\proyectos\tienda\meeko.config.ts: server.port debe ser un entero entre 0 y 65535. In meeko check and meeko build, the error also starts with the file's TS2322, including its line and column.
// meeko.config.ts
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ server: { adapter: "node", port: 8080 } });Two configuration files#
meeko.config.ts
meeko.config.mjsError: Hay varios archivos de configuración de Meeko: C:\proyectos\tienda\meeko.config.ts, C:\proyectos\tienda\meeko.config.mjs. Keep just one.
meeko.config.tsExpect a misspelled key to be rejected#
export default defineMeekoConfig({ sitemapp: true });loadMeekoConfig validates values of known keys and returns others unchanged: { sitemapp: true } loads and the option does nothing. Since 1.7 it warns once per configuration on standard error: [meeko] Aviso: meeko.config.ts tiene la clave desconocida "sitemapp", que Meeko ignora. ¿Quisiste decir "sitemap"?. With modules, the warning comes when loading modules (meeko dev, meeko build, meeko check), because their meta.configKey values are also valid keys. It is a warning rather than an error because that configuration loaded in 1.6; tsc does not detect it because defineMeekoConfig's type accepts module keys that do not augment MeekoConfig. Through 1.6, there was no warning.
import { defineMeekoConfig } from "@meekojs/meeko/framework";
export default defineMeekoConfig({ site: "https://example.com", sitemap: true });Notes#
- Executes code. Importing configuration executes
meeko.config.tsand its imports with Node: use it only with trusted projects. - TypeScript. Node 24 strips types on import: non-erasable TypeScript syntax (
enum,namespacewith values) does not work in configuration. - Messages. Since
1.7,meeko.config.tsand theme validation errors are in Spanish (server.port debe ser un entero entre 0 y 65535);document.head,document.seoandserver.contentSecurityPolicyerrors, which share validation withuseHeadand the CSP header, remain in English. - Environment variables. Does not read
.env; if configuration usesprocess.env, load it first (the CLI does so indev,build,start,previewandcheck). - Cache. File content is part of the import URL: if unchanged, Node reuses the loaded module without executing it again; if changed, it loads the new version. Modules imported by configuration do remain in Node's cache throughout the process.