Pods
A pod is a self-contained bundle of routes, custom elements, bundles, and CMS collections that a plugin merges into your site, laid out just like a regular Root.js project. Use pods when a plugin needs to provide pages or content models (like a custom tool in the CMS sidebar or shared collections across multiple sites) without copying files into every repo.
Defining a pod
A plugin registers a pod with its pod field. The pod's name must be unique across the site, and each directory is an absolute path, so resolve them from the plugin's own file. That way they still work once the plugin is installed from node_modules:
// @/plugins/launches-pod.ts
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import type {Plugin} from '@blinkk/root';
const POD_DIR = path.dirname(fileURLToPath(import.meta.url));
export function launchesPod(): Plugin {
return {
name: 'launches-pod',
pod: {
name: 'launches-pod',
mount: '/internal/launches',
routesDir: path.join(POD_DIR, 'routes'),
elementsDirs: [path.join(POD_DIR, 'elements')],
collectionsDir: path.join(POD_DIR, 'collections'),
},
};
}
// @/root.config.ts
import {defineConfig} from '@blinkk/root';
import {launchesPod} from './plugins/launches-pod';
export default defineConfig({
plugins: [launchesPod()],
});
pod can also be an array of pods, or a function that receives {rootConfig} and returns a pod or array of pods (synchronously or as a promise) when the pod depends on site config. Wrap a standalone pod in definePod() for type checking. Every directory is optional; see Pod in the API reference for all fields.
The dev server watches pod directories too, so adding or deleting files reloads the page just like in your own project.
Routes
Files in routesDir follow the same rules as routes/: index.tsx serves its directory, [slug].tsx and catch-alls take params, getStaticPaths() lists the pages to prerender, and files starting with _ are skipped. They're served under the pod's mount, which defaults to /. With the pod above, routes/index.tsx serves /internal/launches and routes/[id].tsx serves /internal/launches/<id>.
The site's base and localized URL format apply to pod routes too, and root build prerenders them alongside your own. Avoid overlapping pod URLs with site routes, since precedence isn't guaranteed; change the mount or exclude the route instead (see below).
Routes are keyed by file path, so two pods can't share one routesDir. If a plugin registers the same pages more than once, e.g. at two mounts, give each pod its own directory and re-export the page from a shared module.
Elements and bundles
Each directory in elementsDirs is scanned like elements/, so a page that uses one of the pod's custom elements loads it automatically, whether the page comes from the pod or from your site. Tag names share one namespace with your own elements, so prefix them with something specific to the pod.
Scripts at the top level of bundlesDir are built with your bundles/.
CMS collections
Every *.schema.ts file in collectionsDir becomes a collection in the CMS, named after its file the same as your own schemas, and is included in the generated root-cms.d.ts types. If the site has a collection with the same id, the site's own schema is used and the pod's is ignored. That makes it possible to override a pod's schema by copying it into collections/ and editing it.
If two pods define the same collection id, Root.js throws an error. Use collections.rename to rename one of them, and do it before saving any docs since it changes the id stored in the CMS.
Opening a pod in the CMS
You can embed a pod's pages inside the CMS by pointing a sidebar tool at its mount. For example, here's how rootjs.dev wires up its Templates tool:
// @/root.config.ts
export default defineConfig({
plugins: [
templatesPod(), // Mounted at /cms-tools/templates.
cmsPlugin({
// ...
sidebar: {
tools: {
templates: {
label: 'Templates',
iframeUrl: '/cms-tools/templates/',
},
},
},
}),
],
});
Configuring a pod
The pods option in root.config.ts lets a site override a pod's settings by name. You can disable a pod, change its mount, or exclude and rename its routes and collections:
// @/root.config.ts
export default defineConfig({
plugins: [launchesPod(), blogPod()],
pods: {
'launches-pod': {
mount: '/tools/launches',
routes: {
exclude: ['archive/', /\.preview\.tsx$/],
},
},
'blog-pod': {
collections: {
exclude: ['Authors'],
rename: {Posts: 'BlogPosts'},
},
},
'legacy-pod': {
enabled: false,
},
},
});
A string in routes.exclude skips every route file whose path, relative to the pod's routesDir, contains it, and a regex is tested against that path. collections.exclude and the keys in collections.rename are the pod's own collection ids. For the full list, see PodConfig in the API reference.