Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewESMPlugin ¶
func NewESMPlugin(opts ESMOptions) (api.Plugin, error)
NewESMPlugin builds an esbuild plugin that turns the build into a Deno-style "import from the network" resolver: every bare import (e.g. "framer-motion") is rewritten to an esm.sh URL, fetched over HTTP, cached on disk, and handed back to esbuild as a normal module. Sub-imports emitted by esm.sh (absolute "/...", full "https://..." or — when ?external is used — bare "react") are resolved recursively against the importing URL.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder turns .mdx files into self-contained, server-rendered + hydrated HTML pages using esbuild (bundling), esm.sh (npm resolution) and goja (in-process SSR). It holds no per-page state and is safe to reuse.
func New ¶
New constructs a Builder, validating the app directory and building the shared esm.sh resolver plugin up front so its cache is reused across pages.
func (*Builder) BuildPage ¶
BuildPage runs the full pipeline for one .mdx file:
read .mdx -> mdxgo.Compile (MDX -> ESM React module) -> esbuild pass 1 (bundle a server entry) -> goja (renderToStaticMarkup) -> esbuild pass 2 (bundle a client entry) -> hydration asset -> write index.html + <asset>.js (+ <asset>.css)
type ESMOptions ¶
type ESMOptions struct {
// CDN is the base URL used to resolve bare specifiers. Defaults to
// "https://esm.sh".
CDN string
// CacheDir is the directory used to persist downloaded modules between
// builds. If empty, a directory under os.UserCacheDir is used. The cache is
// keyed by the full request URL, so pinned/versioned URLs are immutable and
// safe to cache forever.
CacheDir string
// ReactVersion pins the React major/minor used both for "react"/"react-dom"
// themselves and for the ?external= dedupe of every other package. Defaults
// to "18.3.1".
ReactVersion string
// Target is forwarded to esm.sh as ?target= so the CDN ships syntax our
// downstream esbuild pass can consume. Defaults to "es2020".
Target string
// Dev appends ?dev to package URLs, pulling React's development builds with
// warnings. Leave false for production output.
Dev bool
// HTTPTimeout bounds each individual module download. Defaults to 30s.
HTTPTimeout time.Duration
}
ESMOptions configures the esm.sh resolver plugin.
type Options ¶
type Options struct {
// AppDir holds the React shell on disk: App.tsx, entry files, components and
// index.css. Bare imports inside it (react, framer-motion, ...) are resolved
// from esm.sh; relative imports are resolved on disk by esbuild as usual.
AppDir string
// CacheDir is the on-disk cache for downloaded esm.sh modules. When empty a
// directory under the user cache dir is used.
CacheDir string
// ReactVersion pins the React used for SSR and hydration. Defaults to 18.3.1.
ReactVersion string
// Dev produces unminified client bundles and React development builds.
Dev bool
// TailwindCDN, when set, injects a <script> in the page head (e.g. the
// Tailwind v4 browser build). The default shell ships hand-written, bundled
// CSS and needs no runtime Tailwind, so this is empty by default.
TailwindCDN string
// CustomCSSURL, when set, is linked last in the page head so a project's
// static/custom.css can override the default theme tokens (e.g. to change
// the accent color) without modifying the core.
CustomCSSURL string
}
Options configures a Builder. AppDir is the only required field.
type PageInput ¶
type PageInput struct {
MDXPath string // absolute path to the .md/.mdx source (optional if Source is set)
Source []byte // inline MDX source; when non-nil, used instead of reading MDXPath
OutDir string // directory to write the page + assets into
OutFile string // output filename (default "index.html"); e.g. "404.html"
URLPath string // canonical URL path, e.g. "/docs/intro/"
AssetName string // base name for emitted assets ("intro" -> intro.js)
Title string // <title> and og:title
Heading string // when set, rendered as the page's H1 (from frontmatter title)
Description string // meta description
Props map[string]any // arbitrary props forwarded to <App>
}
PageInput describes a single page to render.