Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

meeko compile

Checks a .meeko component and compiles it to a TypeScript module with its server render, hydration and types.

command Since 1.0.0

meeko compile translates a .meeko component to the TypeScript module run by the server and browser: renderWithState and renderToString for SSR, hydrate for the browser, the component's CSS and the types for its props, events, models and snippets. It first checks it like meeko check with a component; if there are errors, it writes nothing.

You do not need it in an application: the Vite plugin compiles each .meeko when imported. Use it to see what the compiler generates, debug a component or integrate it into a build system other than Vite.

Usage#

sh
meeko compile app/components/Greeting.meeko Greeting.generated.ts
texto
Greeting.generated.ts

Type#

sh
meeko compile <componente.meeko> <salida.ts>

Parameters#

Parameter Type Default Description
<componente.meeko> path required The component. Its imports and auto-imports resolve from its folder and project.
<salida.ts> path required The file to write. Overwritten if it exists; its folder must exist.

Result#

Without errors, it writes the module, prints the output path as provided and exits with code 0. With errors, it prints diagnostics, does not write the file and exits with code 1.

ts
// Greeting.generated.ts (extracto)
// Generated by Meeko. Edit the .meeko source instead.
import * as __meeko from "@meekojs/meeko/internal";

export type ComponentProps = { name: string };
export const css = "";
export function renderWithState(__inputProps: ComponentProps): { html: string; state: __meeko.HotState } {
  // …
}

The module imports @meekojs/meeko/internal, so it runs with the same @meekojs/meeko version used to compile it. It follows the css.scopeAttribute and theme options from the meeko.config.ts of the project containing the component.

Examples#

See what a directive generates#

sh
meeko compile app/components/Counter.meeko ../counter.ts

Comparing the module before and after a change shows how the compiler translates on:, if:when or each:of to direct DOM bindings, without a virtual DOM.

Use the module in a custom server#

ts
// server.ts
import { renderWithState } from "./Greeting.generated.ts";
import { serializeJson } from "@meekojs/meeko";

const props = { name: "Ada" };
const { html, state } = renderWithState(props);
const page = `<div id="app">${html}</div><script type="application/json" id="data">${serializeJson({ props, state })}</script>`;

The browser must hydrate with the same props; meeko init creates a complete project with this structure.

Common mistakes#

A component with errors#

Incorrectmeeko
<!-- app/components/Broken.meeko -->
<script lang="ts">
const n: number = "x";
</script>
<template><p>{n}</p></template>
texto
C:\proyectos\tienda\app\components\Broken.meeko:2:7 TS2322: Type 'string' is not assignable to type 'number'.

The output file is not created and the exit code is 1.

Correctmeeko
<!-- app/components/Broken.meeko -->
<script lang="ts">
const n: number = 1;
</script>
<template><p>{n}</p></template>

Forget the output file#

Incorrectsh
meeko compile app/components/Greeting.meeko

Falta el archivo de salida de compile, with usage information and exit code 1. Output does not go to stdout.

Correctsh
meeko compile app/components/Greeting.meeko Greeting.generated.ts

A standalone component outside a project#

Incorrectsh
# Card.meeko in a directory without node_modules or tsconfig.json
meeko compile Card.meeko Card.ts

Falló la comprobación con TypeScript 7: error TS2688: Cannot find type definition file for 'node'. Without a tsconfig.json, the initial check uses default options that include Node types, and requires @types/node (and @meekojs/meeko) installed in the component's project.

Correctsh
# inside a project with @meekojs/meeko and @types/node installed
meeko compile app/components/Card.meeko Card.ts

Notes#

  • The format is not stable. The generated module is internal: its shape may change between minor versions. Always compile with the same version you run it with.
  • Same as Vite. The Vite plugin uses the same compiler; what meeko compile generates is what meeko dev and meeko build run, except for HMR and DevTools code, which only exists in development.
  • Performance. Compilation is fast; the initial TypeScript check takes the time.
  • Windows and POSIX. Input and output paths accept \ or /.

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: docs/en/reference/commands/meeko-compile.md