MarkdownVite unstable
A Vite plugin that compiles imported .md files at build time into
document modules, so no parser ships to the browser.
Each module's default export is the encoded document; decode it with
Markdown.decodeDocument and render it with Markdown.view. Each module
also exports frontmatter: the checked fields when the plugin has a
frontmatter schema and the file has a frontmatter block, and
undefined otherwise. Source outside the vocabulary fails the build with
the construct and its line.
Add effect/ui/html/MarkdownContent to compilerOptions.types for the
*.md module types.
Example Configuring the plugin
import { markdown } from "effect/ui/html/MarkdownVite"import { Schema } from "effect"
// vite.config.ts: export default { plugins: [plugin] }const plugin = markdown({ frontmatter: Schema.Struct({ title: Schema.String }), islands: { Counter: Schema.Struct({ label: Schema.optionalKey(Schema.String) }) }})
const compiled = plugin.transform("---\ntitle: Hello\n---\n\n::Counter", "/posts/hello.md")compiled?.code.split("\n")[1] // => 'export const frontmatter = {"title":"Hello"}'Constructors
Models
The subset of a Vite plugin that markdown returns. It is assignable to
Vite's Plugin without importing vite.
Signature
interface Plugin { readonly name: string; readonly transform: (source: string, id: string) => TransformResult | undefined;} Since v4.2.0 Source
The module code a .md file compiles to.
Signature
interface TransformResult { readonly code: string; readonly map: null;}