Skip to Content
Octopus Energy Packages

Configuration

Compose presets, override defaults, and configure executables and docs

Compose and override

Add presets with withPresets() and put any tsdown option alongside presets:

tsdown.config.ts
import { library, validate, withPresets } from "@octopus-energy/tsdown";

export default withPresets({
  presets: [library(), validate()],
  entry: "src/index.ts",
  minify: false,
});

Presets are applied in order, followed by your configuration:

  • Later scalar values win.
  • Objects merge deeply.
  • Arrays, entries, hooks, and custom exports compose in declaration order.

See the API reference for preset defaults and dependencies. The examples below show additions to the presets array; import each preset from @octopus-energy/tsdown.

Set preset options

Pass options directly to a preset. For example, run the React Compiler only in CI:

react({ compiler: "ci-only" });

For compiler settings, pass an object instead:

react({ compiler: { enabled: "ci-only", target: "19" } });

See the react() API for all compiler options.

Add executables

Declare executable names and source files with cli():

cli({ bin: { "oe.example": "./src/cli/index.ts" } });

This builds dist/oe.example.mjs and generates bin metadata. Binary entries are excluded from normal package exports by default.

  • To also export a library, add entry: "src/index.ts" alongside presets.
  • Development exports and binaries point to source files; published metadata points to build output. Set exports: { devExports: false } alongside presets if the source cannot run directly in your supported Node.js versions.

See the cli() API for aliases and selective export exclusions.

Embed documentation

Add docs() to copy docs/ to dist/docs/ and generate a page catalog at dist/docs/index.json with the default build output directory.

  • The source directory must exist.
  • Markdown and MDX pages need a frontmatter title; description is optional.
  • Other files are copied unchanged as assets.
  • Include the output in your published package, for example with "files": ["dist"] in package.json.

To customize directories or skip drafts:

docs({
  source: "content",
  output: "manual",
  exclude: ["**/drafts/**"],
});

source is relative to the package root; output is relative to tsdown's output directory. This example writes to dist/manual/ when using the default build output.

Use transform to render custom MDX components or rewrite document source, paths, and metadata. Import the renderer explicitly in your build configuration:

import { createPackageDocsTransform } from "@oe/docs-transform";

import { markdownRenderers } from "./docs/markdown.ts";

docs({
  transform: createPackageDocsTransform({ renderers: markdownRenderers }),
});

The preset excludes components.ts, components.tsx, and markdown.ts from bundled documentation. In watch mode, it adds the docs directory to tsdown’s native watch paths. tsdown reloads configuration imports when they change, including the renderer’s imported data. See the docs() API for options and validation.

Reuse custom configuration

A custom preset is a function that returns a UserConfig. No registration is needed:

import type { UserConfig } from "tsdown";

function sourcemaps(): UserConfig {
  return { sourcemap: true };
}

Add it to your presets: presets: [library(), sourcemaps(), validate()]. For a one-off change, set sourcemap: true alongside presets instead.

On this page