Using a plugin
A Récit plugin is an ordinary npm package, added to recit.. It can bring directives and
components for your decks and pages, blocks for your films, themes, recit export -- targets,
data sources, commands and AI jobs.
The plugin API is experimental, except for the
v1 data source contract. Outside that contract, its names may
change in a minor release, with a note in the changelog. Only the plugins key of the config and
the data source contract are in the v1 stability promise. See
Stability.
Add one
Bash
TypeScript
A plugin is a function: you call it with its options, and Récit checks them when it loads the plugin, before anything else. A plugin written for another version of the plugin API is refused, with what to update.
recit plugins lists the plugins of the project, their version, what each one brings, and the
weight each added to the page at the last build. recit build warns past 30 kB brotli per plugin
(--plugin-); the build of a site weighs its plugins the same way and takes its budget
from publish. (kB) in its recit.config.
What a plugin brings
| Capability | How you use it |
|---|---|
| Directives | :::lorem- in a story, in Markdown and in its twin |
| Components | mounted in the browser, loaded only by a slide that uses them |
| Film blocks | a scene type= in a film |
| Themes | theme:, for a deck or a film |
| Exporters | recit export slides. |
| Sources | data:, read at build time |
| Commands | recit lorem hello, always prefixed with the plugin's name |
| AI jobs | recit ai deck. (AI jobs) |
A directive of a plugin has a schema: recit validate checks it in a .md and in a .json alike,
and recit schema adds it to the JSON Schema of the project. A story that uses a plugin's directive
or block needs that plugin to build: without it, recit validate says plugin-.
Secrets
A key, a token or a license is never written in the config. A plugin takes the name of an
environment variable, { env:, and reads it at build time or when a job runs; a key
written in clear is refused. Nothing a plugin reads at build time reaches the built site: a data
source is read in Node, and only its rows go to the page.
Security
- A plugin is code you install. It runs with your rights, like a Vite plugin. Récit does not isolate it and does not check it.
- Install a plugin as a dependency: read who publishes it, pin its version.
- An AI plugin sends your content to a service: the provider (your key) or the plugin's author (its license). The plugin must say so in its README.
- Your keys go in environment variables (
{ env }), never in the config nor in the published site.
In a site
A site evaluates its recit. in the browser too. Every plugin package it imports must
serve a browser entry, which holds its components and nothing else, so that its schemas and its
Node code never reach a visitor. Writing a plugin shows the two
entries. recit validate, recit plugins and the site build report a package without one
(plugin-), and the build stops.
The stories of a site (publish.dir) render the plugins' directives and mount their components, as
a deck built by recit build does: list the plugin in the one plugins array of the site's
recit., beside the site's own plugins.
The Markdown and MDX pages of the site render them too. A static directive (::lorem-) becomes
the plugin's element; an interactive one (:::lorem-) mounts the plugin's component, with
its attributes as props and its content as children, and the component loads with the page. A
directive the plugin refuses stops the build with the page and its line, as in a story. In an MDX
page, the plugin's component is also there by its name: <LoremCounter start=. A component of
the site with the same name wins.
Limits (experimental)
- An
.mdxdeck does not render a plugin's directives. Write the deck in.mdto use them. - The plugin API is outside the v1 stability promise, except for the v1 data source contract (Stability): the rest may change in a minor release.