Write a plugin and publish it
Goal: create a Récit plugin package, give it one static directive, test it, draw it in a deck
with recit build, and publish the package on npm.
The plugin API is experimental, except for the
v1 data source contract: it may change in a minor release
(Stability). Pin the version of recit your
plugin peers on.
This guide follows the reference plugin of the repository, examples/, and the deck
that uses it, examples/. For every capability (components, film blocks, themes,
exporters, data sources, commands, AI jobs), see Writing a plugin.
1. Create the package
Récit is not on npm: create-recit, which holds the template, and the recit packages come as
archives of the private channel (Quickstart). With them
in archives/:
Bash
The plugin template is a copy of examples/: one of each capability, its tests and a
build with tsdown. It needs npm 11 or later (engines.npm): npm 10 crashes while it installs
vitest 4.1. The package takes the name of its folder; call it recit- or
@scope/.
The template names everything lorem, and this guide keeps its names so that each step matches the
files you have. Rename lorem to your own short name (acme) once the guide works: it prefixes
your directives, your diagnostics (acme/) and your commands (recit acme sync).
2. Write the directive
A static directive is a function that returns hast at build
time: the page gets HTML and no script. Open src/quote.ts:
src/quote.ts
- Every text is a hast text node, never raw HTML: Récit sanitises the output like its own directives.
context.raises a diagnostic whose code starts with the plugin's name.report context.holds the options of the plugin, as the config passes them.options
3. Declare it
src/index.ts is the Node entry. It declares the directive, its attributes schema and its module:
src/index.ts
The attributes schema is required: a directive never exists in Markdown only. The schema validates
:::lorem- in a .md and in its JSON twin, and gives its JSON Schema. The render
module is a lazy import(), loaded only by a story that uses the directive.
4. Test the twin round trip
src/__ checks that a story using the directive survives Markdown → JSON
→ Markdown, and reads the HTML it draws:
src/__tests__/unit/index.spec.ts
Run the tests, then build the package:
Bash
npm test calls no network: the AI jobs of the template run against fakeAiProvider of
recit/. The bible job tests of the template need @recit/, a preview
package not published on npm, and are skipped without it, so npm test passes without it.
npm run build writes dist/, the only folder the package ships.
5. Use it in a deck
In a deck project (for example one made by
Write and present your first deck), install the plugin from its
folder, then load it in recit.:
Bash
recit.config.ts
Write the directive in a scene of slides.md:
slides.md
Preview the deck, then build it:
Bash
recit dev loads the browser entry of the plugin; recit build writes the directive's HTML into
dist/, which any static file host can serve.
6. Publish it
Before the first release, edit package.json:
- remove
"private":, which the template sets so that nothing is published by mistake, and settrue version; - keep the
recit-pluginkeyword: that is how people find a plugin on npm; - keep
filestodistandREADME.md: no source, no test, no fixture; - keep the two entries of
exports(browserfor the client bundle,defaultfor Node) and the peers onrecitandzod; - keep the optional peers (
@recit/,motion- blocks @recit/) only for the capabilities your plugin keeps:scenario @recit/, which the bible jobs load, is a preview package not published on npm yet.scenario
Then publish:
Bash
--access public is needed for a scoped name only. To publish without showing your source, or to a
private registry, see Publishing a plugin.
Check
npm testpasses, with the round trip of:::lorem-.quote - In the built deck, the
quoteslide shows a figure with « Neque porro quisquam est qui dolorem ipsum. » and « — Cicero », and the browser console has no error. npm view recit-listsplugin- acme keywords recit-pluginafter the release.
This guide is tested by e2e/: it compares the blocks above with
examples/ and examples/, builds the deck with the plugin and opens the
quote slide.