Skip to content

Build and tsconfig

Two tiers, two module formats

A plugin has two build tiers with different module formats:

Tier Source format Emitted format Loaded by
Main (backend) ESM (import/export) CJS (require/exports) require() in the plugin loader
Renderer (pages, slots) ESM ESM dynamic import() in the renderer

You author both tiers in ESM. The main tier is emitted as CommonJS because the plugin loader calls require(). The renderer tier stays ESM and the host loads it as a module.

Every plugin is built by the same builder, lore-plugin build, which uses esbuild for both tiers. Two entry points run it:

Where the plugin lives Command Notes
Outside the Lore Desktop repository (needs the SDK from npm, which is not published yet) lore-plugin build Minified renderer bundles, sourcemaps written beside the bundles but not linked
In the Lore Desktop repository (packages/plugins/) pnpm build:plugins Runs lore-plugin build's builder over every plugin; renderer bundles are minified with linked sourcemaps because the dev server serves them with their maps

Both type-check all of src/ against the plugin's tsconfig.json before writing anything. lore-plugin dev runs the same build once and again after each change batch, without minification. lore-plugin pack zips the result. The CLI reference is Build, pack, and install a plugin.

dist/ layout

After a build, your plugin's dist/ looks like this:

<plugin>/dist/
├── main.js              ← CJS — your definePluginMain() entry
├── main.js.map
├── renderer.js          ← ESM — your definePluginRenderer() entry (if src/renderer.tsx|ts exists)
├── chunks/*.js          ← ESM — chunks split out of renderer.js (for example lazySlot pages)
├── pages/*.js           ← ESM — one bundle per file directly in src/pages/*.tsx|ts
├── vendor/              ← vendor/ copied verbatim
└── <resources>          ← contents of resources/ copied flat into dist/

plugin.main must point at dist/main.js, and plugin.renderer, when present, at dist/renderer.js. lore-plugin build refuses any other value. Declaring plugin.renderer with no src/renderer.ts or src/renderer.tsx is also an error.

Each build replaces only the outputs it owns: main.js, renderer.js, their .js.map files, pages/ and chunks/. A bundle whose source was renamed or deleted does not linger. Anything else in dist/, such as copied resources and vendor/, is kept.

Entries under src/pages/ are flat and non-recursive: only files directly in src/pages/ become page bundles, and .d.ts files and files with .test. in the name are skipped. A subdirectory of src/pages/ is treated as shared code for the pages.

What the build does

Everything goes through esbuild, after refusal checks that run before the first write:

  1. Manifest checks. package.json is parsed with the same manifest parser the host uses. Then engines.lore must be a valid semver range, plugin.main must be dist/main.js, and plugin.renderer must be dist/renderer.js when src/renderer.ts(x) exists.
  2. Type check. src/ is checked against the plugin's own tsconfig.json through the TypeScript compiler API with noEmit forced. Renderer and page .tsx files are included. Diagnostics are printed tsc-style, and any error exits 1 with dist/ byte-identical to before. TypeScript is resolved from the plugin's node_modules first, then from the SDK's own install. The scaffold adds typescript ^5.8.3 as a devDependency. TypeScript 7 has no compiler API and is refused with a message naming the resolved version and --no-typecheck, so stay on 5.x. --no-typecheck skips this step.

Then, in order:

  • src/main.ts → dist/main.js. The output is CJS for Node. Only electron and the exact @lore-vcs/desktop-plugins-sdk root stay external. SDK subpaths such as /manifest are bundled, because a packed zip ships no node_modules.
  • src/pages/* → dist/pages/.
  • src/renderer.tsx|ts → dist/renderer.js, with code splitting so that lazySlot(() => import("./pages/x")) produces a separate chunk under dist/chunks/. If a lazily imported page is inlined into the renderer entry instead, the build fails.
  • A warning for EDS icon names it could not verify.
  • resources/ and vendor/ are copied.

The renderer outputs are ESM and use the externals listed below. The tiers are built into a staging folder beside dist/ (.dist-*) and merged in only once every tier has succeeded, so a failure in a later tier leaves dist/ exactly as it was.

Note

src/widgets/ is not built. Only src/main.ts, src/pages/* and src/renderer.ts(x) are bundled.

Building a plugin in the repository

Inside the Lore Desktop repository, pnpm build:plugins runs scripts/build-plugins.mjs. The script finds every directory under packages/plugins/ whose package.json has a top-level plugin object and builds each one with lore-plugin build's builder. It imports that builder from the built SDK, so run pnpm build:sdk first. If the SDK build is missing or older than the SDK source, the script stops and tells you to run pnpm build:sdk.

--plugin-root

--plugin-root is an option of the development launcher: pnpm dev -- <repo> --plugin-root <path>. The launcher forwards it to build-plugins.mjs as --root <path>, which replaces packages/plugins/ as the directory the plugin build scans. For a root outside the repository, the script links <root>/node_modules to the repository's node_modules if the root has none, so the SDK and other host-provided packages resolve.

The flag does not affect runtime discovery. The host resolves bundled plugins from a fixed location inside the app bundle, or packages/plugins in development. A plugin built from a custom root builds but is not found at startup unless it also appears in one of the discovery sources listed in Getting started. Plugins outside the repository never use this flag; lore-plugin build takes the plugin directory as its argument.

Externals

The renderer-tier bundles externalize host-provided packages so your plugin does not ship its own copy of React, EDS or the SDK. The SDK owns the canonical list (packages/plugin-sdk/src/externals.ts), published as @lore-vcs/desktop-plugins-sdk/externals. The host's scripts/pluginExternals.mjs is a mirror held exact by a test:

export const PLUGIN_EXTERNALS = [
  "react",
  "react/jsx-runtime",
  "react-dom",
  "react-dom/client",
  "@lore-vcs/desktop-plugins-sdk",
  "@lore-vcs/desktop-plugins-sdk/react",
  "@lore-vcs/desktop-plugins-sdk/renderer",
  "@epicgames/eds-react",
];

If you import any of these, esbuild leaves the import as a bare specifier, and the host's import map resolves it to the shared instance at runtime.

A CommonJS dependency that you bundle into a renderer tier and that calls require("react") works. The builder adds a module-local require shim that resolves react, react-dom and react-dom/client to the host's instances.

EDS icons are not a separate entry. The builder rewrites @epicgames/eds-react/icons/<Name> to a named import off the externalized @epicgames/eds-react barrel, so no icon needs an import-map entry and any icon in the host's EDS version works in a packaged build. Only @epicgames/eds-react/icons/<Name> with a single icon name is accepted. When @epicgames/eds-react is installed in the plugin's tree, as it is for a scaffolded plugin with a renderer, the icon name is checked and a wrong name fails the build. When it is not, as in a hand-written plugin that has not added the peer/dev dependency pair, lore-plugin build prints warning: could not verify N EDS icon import(s) (@epicgames/eds-react not found): …, and a wrong name fails when the host loads the renderer bundle. The plugin's row in the Plugins screen shows the error. See Renderer: React.

Plugin tsconfig.json

esbuild emits every tier, so your tsconfig.json only has to resolve and type-check; nothing is emitted by tsc.

Outside the repository

Note

This applies once @lore-vcs/desktop-plugins-sdk is published to npm. Until then, author plugins inside the repository.

lore-plugin create writes this tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "lib": ["ES2022", "DOM"],
    "jsx": "react-jsx",
    "types": ["node"],
    "noEmit": true,
    "strict": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "isolatedModules": true
  },
  "include": ["src/**/*"],
  "exclude": ["dist", "node_modules", "**/__tests__"]
}

No .tsx exclusion is needed or wanted. moduleResolution: "bundler" resolves the SDK's exports and @epicgames/eds-react, and lore-plugin build type-checks the whole tree, renderer and pages included.

In the repository

A plugin scaffolded inside the Lore Desktop repository extends a shared base, packages/plugins/tsconfig.base.json, which holds the same compiler options as the outside-the-repository scaffold plus the include and exclude globs. The plugin's own tsconfig.json adds only what that plugin needs:

{
  "extends": "../../tsconfig.base.json"
}

The path in extends is relative to the plugin directory, so it is ../../tsconfig.base.json for a scoped plugin such as packages/plugins/@lore/branch-explorer. @lore/branch-explorer uses exactly this.

There is no CommonJS compilation step and no need to exclude renderer-tier files from the type check.

TypeScript resolution of SDK subpaths

The SDK declares its subpaths in exports: @lore-vcs/desktop-plugins-sdk, /react, /renderer, /externals and /manifest. Under "moduleResolution": "bundler", which both scaffolds use, TypeScript reads exports directly and nothing more is needed. For a project that uses "moduleResolution": "Node", a typesVersions block in the SDK's package.json maps each subpath to its .d.ts, so the same imports resolve there too. No paths alias is needed.

Next

Worked examples walks through a complete plugin end to end, tying together everything from manifest to build output.