Interface: LoadContext

Defined in: index.ts:111

What a loader's load receives.

Example

const pages: Loader = {
  load: async ({ collection, root }) => ({
    entries: JSON.parse(await readFile(path.join(root, `data/${collection}.json`), "utf-8")),
  }),
};

Properties

collection

collection: string;

Defined in: index.ts:113

The name of the collection, eg posts.


dev

dev: boolean;

Defined in: index.ts:115

Whether the Vite dev server is running, as opposed to a build.


root

root: string;

Defined in: index.ts:117

The project root, as an absolute path.


watch

watch: (patterns: Glob | readonly Glob[]) => void;

Defined in: index.ts:135

Reruns load in dev when a file matching these globs changes. Patterns are relative to the project root; start one with ! to leave files out. A ! pattern only leaves out files from the same call, so loaders that call each other's load keep their own globs. Without a call, load reruns only when the config changes.

const authors: Loader = {
  load: async ({ root, watch }) => {
    watch("data/authors.json");
    return { entries: JSON.parse(await readFile(path.join(root, "data/authors.json"), "utf-8")) };
  },
};