跳到正文

Interface: UserConfig ​

Defined in: src/config/types.ts:158

Options for tsdown.

Extended by ​

Properties ​

alias? ​

ts
alias?: Record<string, string>;

Defined in: src/config/types.ts:180


attw? ​

ts
attw?: WithEnabled<AttwOptions>;

Defined in: src/config/types.ts:581

Run arethetypeswrong after bundling. Requires @arethetypeswrong/core to be installed.

Default ​

ts
false

See ​

https://github.com/arethetypeswrong/arethetypeswrong.github.io


ts
banner?: ChunkAddon;

Defined in: src/config/types.ts:408


checks? ​

ts
checks?: ChecksOptions & object;

Defined in: src/config/types.ts:337

Controls which warnings are emitted during the build process. Each option can be set to true (emit warning) or false (suppress warning).

Type Declaration ​

legacyCjs? ​
ts
legacyCjs?: boolean;

If the config includes the cjs format and one of its targets is a Node.js version that supports require(esm) (^20.19.0 || >=22.12.0), warn the user about the deprecation of CommonJS.

Default ​
ts
true

cjsDefault? ​

ts
cjsDefault?: boolean;

Defined in: src/config/types.ts:458

Converts a single default export from an explicit CJS entry module to module.exports. It does not apply to non-entry chunks emitted in unbundle mode.

Default ​

ts
true

clean? ​

ts
clean?: boolean | string[];

Defined in: src/config/types.ts:402

Clean directories before build.

Default to output directory.

Default ​

ts
true

copy? ​

ts
copy?:
  | CopyOptions
  | CopyOptionsFn;

Defined in: src/config/types.ts:625

Copy files to another directory.

Example ​

ts
;[
  'src/assets',
  'src/env.d.ts',
  'src/styles/**/*.css',
  { from: 'src/assets', to: 'dist/assets' },
  { from: 'src/styles/**/*.css', to: 'dist', flatten: true },
]

css? ​

ts
css?: CssOptions;

Defined in: src/config/types.ts:610

[experimental] CSS options. Requires @tsdown/css to be installed.


customLogger? ​

ts
customLogger?: Logger;

Defined in: src/config/types.ts:511

Custom logger.


cwd? ​

ts
cwd?: string;

Defined in: src/config/types.ts:481

The working directory of the config file.

  • Defaults to process.cwd | process.cwd() for root config.
  • Defaults to the package directory for workspace config.

Default ​

ts
process.cwd()

define? ​

ts
define?: Record<string, string>;

Defined in: src/config/types.ts:258


deps? ​

ts
deps?: DepsConfig;

Defined in: src/config/types.ts:178

Dependency handling options.


devtools? ​

ts
devtools?: WithEnabled<DevtoolsOptions>;

Defined in: src/config/types.ts:540

[experimental] Enable devtools.

DevTools is still under development, and this is for early testers only.

This may slow down the build process significantly.

Default ​

ts
false

dts? ​

ts
dts?: WithEnabled<DtsOptions>;

Defined in: src/config/types.ts:558

Enables generation of TypeScript declaration files (.d.ts).

By default, this option is auto-detected:

  • If exe is enabled, declaration file generation is disabled by default.
  • If the types or typings field is present in package.json, or if its exports field contains a types entry, declaration file generation is enabled by default.
  • Otherwise, if the resolved tsconfig.json has declaration: true, declaration file generation is enabled by default.
  • Otherwise, declaration file generation is disabled by default.

entry? ​

ts
entry?: TsdownInputOption;

Defined in: src/config/types.ts:173

Defaults to 'src/index.ts' if it exists.

Supports glob patterns with negation to exclude files:

Example ​

ts
entry: {
  "hooks/*": ["./src/hooks/*.ts", "!./src/hooks/index.ts"],
}

Default ​

ts
{
  index: 'src/index.ts'
}

env? ​

ts
env?: Record<string, any>;

Defined in: src/config/types.ts:243

Compile-time env variables, which can be accessed via import.meta.env or process.env.

Example ​

json
{
  "DEBUG": true,
  "NODE_ENV": "production"
}

Default ​

ts
{
}

envFile? ​

ts
envFile?: string | string[];

Defined in: src/config/types.ts:252

Path(s) to env files providing compile-time env variables.

Files are loaded in order, so later files override earlier ones. Missing files are skipped.

Example ​

ts
`.env`, `['.env', '.env.local']`, etc.

envPrefix? ​

ts
envPrefix?: string | string[];

Defined in: src/config/types.ts:257

When loading env variables from envFile, only include variables with these prefixes.

Default ​

ts
'TSDOWN_'

exe? ​

ts
exe?: WithEnabled<ExeOptions>;

Defined in: src/config/types.ts:638

[experimental] Bundle as executable using Node.js SEA (Single Executable Applications).

This will bundle the output into a single executable file using Node.js SEA. Note that this is only supported on Node.js 25.7.0 and later, and is not supported in Bun or Deno.

Default ​

ts
false

exports? ​

ts
exports?: WithEnabled<ExportsOptions>;

Defined in: src/config/types.ts:604

Generate package exports for package.json.

This will set the exports field in package.json to point to the generated files.

Default ​

ts
false

external? ​

ts
external?: string | RegExp | (string | RegExp)[] | ExternalOptionFunction;

Defined in: src/config/types.ts:654

Cannot be combined with deps.neverBundle; setting both throws an error.

Deprecated ​

Use deps.neverBundle instead.


failOnWarn? ​

ts
failOnWarn?: boolean | CIOption;

Defined in: src/config/types.ts:499

If true, fails the build on warnings.

Default ​

ts
false

fixedExtension? ​

ts
fixedExtension?: boolean;

Defined in: src/config/types.ts:437

Use a fixed extension for output files. The extension will always be .cjs or .mjs. Otherwise, it will depend on the package type.

Defaults to true if platform is set to node, false otherwise.

Default ​

ts
platform === 'node'

ts
footer?: ChunkAddon;

Defined in: src/config/types.ts:407


format? ​

ts
format?:
  | "es" | "cjs" | "iife" | "umd" | "commonjs" | "module" | "esm"
  | ("es" | "cjs" | "iife" | "umd" | "commonjs" | "module" | "esm")[]
| Partial<Record<"es" | "cjs" | "iife" | "umd" | "commonjs" | "module" | "esm", Partial<ResolvedConfig>>>;

Defined in: src/config/types.ts:374

Output format(s). Available formats are

  • esm: ESM
  • cjs: CommonJS
  • iife: IIFE
  • umd: UMD

Default ​

ts
'esm'

fromVite? ​

ts
fromVite?: boolean | "vitest";

Defined in: src/config/types.ts:520

Reuse config from Vite or Vitest (experimental)

Default ​

ts
false

globalName? ​

ts
globalName?: string;

Defined in: src/config/types.ts:375


globImport? ​

ts
globImport?: boolean;

Defined in: src/config/types.ts:594

import.meta.glob support.

See ​

https://vite.dev/guide/features.html#glob-import

Default ​

ts
true

hash? ​

ts
hash?: boolean;

Defined in: src/config/types.ts:449

If enabled, appends hash to chunk filenames.

Default ​

ts
true

hooks? ​

ts
hooks?:
  | Partial<TsdownHooks>
  | ((hooks) => Awaitable<void>);

Defined in: src/config/types.ts:627


ignoreWatch? ​

ts
ignoreWatch?: Arrayable<string | RegExp>;

Defined in: src/config/types.ts:529

Files or patterns to not watch while in watch mode.


inputOptions? ​

ts
inputOptions?:
  | InputOptions
  | ((options, format, context) => Awaitable<void | InputOptions | null>);

Defined in: src/config/types.ts:354

Use with caution; ensure you understand the implications.


loader? ​

ts
loader?: ModuleTypes;

Defined in: src/config/types.ts:288

Sets how input files are processed. For example, use 'js' to treat files as JavaScript or 'base64' for images. Lets you import or require files like images or fonts.

Example ​

json
{ ".jpg": "asset", ".png": "base64" }

logLevel? ​

ts
logLevel?: LogLevel;

Defined in: src/config/types.ts:494

Log level.

Default ​

ts
'info'

minify? ​

ts
minify?: boolean | "dce-only" | MinifyOptions;

Defined in: src/config/types.ts:406

Default ​

ts
'dce-only'

name? ​

ts
name?: string;

Defined in: src/config/types.ts:488

The name to show in CLI output. This is useful for monorepos or workspaces. When using workspace mode, this option defaults to the package name from package.json. In non-workspace mode, this option must be set explicitly for the name to show in the CLI output.


nodeProtocol? ​

ts
nodeProtocol?: boolean | "strip";

Defined in: src/config/types.ts:332

Control whether built-in Node.js module imports use the node: protocol.

  • true: Add the node: prefix to built-in module imports.
  • 'strip': Remove the node: prefix from built-in module imports.
  • false: Do not transform built-in module imports.

Default ​

ts
false

Examples ​

`nodeProtocol: true` — add the `node:` prefix
ts
// Input
import 'fs'

// Output
import 'node:fs'
`nodeProtocol: 'strip'` — remove the `node:` prefix
ts
// Input
import 'node:fs'

// Output
import 'fs'
`nodeProtocol: false` — do not transform imports
ts
// Input
import 'node:fs'

// Output
import 'node:fs'

noExternal? ​

ts
noExternal?:
  | Arrayable<string | RegExp>
  | NoExternalFn;

Defined in: src/config/types.ts:659

Cannot be combined with deps.alwaysBundle; setting both throws an error.

Deprecated ​

Use deps.alwaysBundle instead.


onSuccess? ​

ts
onSuccess?: string | ((config, signal) => void | Promise<void>);

Defined in: src/config/types.ts:545

You can specify command to be executed after a successful build, specially useful for Watch mode


outDir? ​

ts
outDir?: string;

Defined in: src/config/types.ts:379

Default ​

ts
'dist'

outExtensions? ​

ts
outExtensions?: OutExtensionFactory;

Defined in: src/config/types.ts:443

Custom extensions for output files. fixedExtension will be overridden by this option.


outputOptions? ​

ts
outputOptions?:
  | OutputOptions
  | ((options, format, context) => Awaitable<void | OutputOptions | null>);

Defined in: src/config/types.ts:463

Use with caution; ensure you understand the implications.


platform? ​

ts
platform?: "node" | "neutral" | "browser";

Defined in: src/config/types.ts:198

Specifies the target runtime platform for the build.

  • node: Node.js and compatible runtimes (e.g., Deno, Bun). For CJS format, this is always set to node and cannot be changed.
  • neutral: A platform-agnostic target with no specific runtime assumptions.
  • browser: Web browsers.

Default ​

ts
'node'

See ​

https://tsdown.dev/options/platform


plugins? ​

ts
plugins?: TsdownPluginOption;

Defined in: src/config/types.ts:349


publint? ​

ts
publint?: WithEnabled<PublintOptions>;

Defined in: src/config/types.ts:572

Run publint after bundling. Requires publint to be installed.

Default ​

ts
false

report? ​

ts
report?: WithEnabled<ReportOptions>;

Defined in: src/config/types.ts:587

Enable size reporting after bundling.

Default ​

ts
true

root? ​

ts
root?: string;

Defined in: src/config/types.ts:425

Specifies the root directory of input files, similar to TypeScript's rootDir. This determines the output directory structure.

By default, the root is computed as the common base directory of all entry files.

See ​

https://www.typescriptlang.org/tsconfig/#rootDir


shims? ​

ts
shims?: boolean;

Defined in: src/config/types.ts:270

Inject CJS __dirname and __filename shims into ESM output. Only applies when platform is set to node.

Note: import.meta.url, import.meta.dirname, and import.meta.filename are always shimmed in CJS output, regardless of this option.

See ​

https://tsdown.dev/options/shims

Default ​

ts
false

sourcemap? ​

ts
sourcemap?: Sourcemap;

Defined in: src/config/types.ts:395

Whether to generate source map files.

Note that this option will always be true if you have `declarationMap` option enabled in your tsconfig.json.

Default ​

ts
false

suppressWarnings? ​

ts
suppressWarnings?: Arrayable<string | RegExp> | ((msg) => boolean);

Defined in: src/config/types.ts:507

Suppress warnings whose message matches the given pattern(s).

Accepts a string (substring match), a RegExp, an array of either, or a predicate function. Matched warnings are dropped before failOnWarn is applied, so they won't fail the build.


target? ​

ts
target?: string | false | string[];

Defined in: src/config/types.ts:229

Specifies the compilation target environment(s).

Determines the JavaScript version or runtime(s) for which the code should be compiled. If not set, defaults to the value of engines.node in your project's package.json. If no engines.node field exists, no syntax transformations are applied.

Accepts a single target (e.g., 'es2020', 'node18', 'baseline-widely-available'), an array of targets, or false to disable all transformations.

See ​

https://tsdown.dev/options/target#supported-targets for a list of valid targets and more details.

Examples ​

jsonc
// Target a single environment
{ "target": "node18" }
jsonc
// Target multiple environments
{ "target": ["node18", "es2020"] }
jsonc
// Disable all syntax transformations
{ "target": false }

treeshake? ​

ts
treeshake?: boolean | TreeshakingOptions;

Defined in: src/config/types.ts:277

Configure tree shaking options.

See ​

https://rolldown.rs/reference/InputOptions.treeshake for more details.

Default ​

ts
true

tsconfig? ​

ts
tsconfig?: string | boolean;

Defined in: src/config/types.ts:185

Default ​

ts
true

unbundle? ​

ts
unbundle?: boolean;

Defined in: src/config/types.ts:415

Determines whether unbundle is enabled. When set to true, the output files will mirror the input file structure.

Default ​

ts
false

unused? ​

ts
unused?: WithEnabled<Options>;

Defined in: src/config/types.ts:565

Enable unused dependencies check with unplugin-unused Requires unplugin-unused to be installed.

Default ​

ts
false

watch? ​

ts
watch?: boolean | Arrayable<string>;

Defined in: src/config/types.ts:525

Default ​

ts
false

workspace? ​

ts
workspace?: true | Arrayable<string> | Workspace;

Defined in: src/config/types.ts:644

[experimental] Enable workspace mode. This allows you to build multiple packages in a monorepo.


write? ​

ts
write?: boolean;

Defined in: src/config/types.ts:385

Whether to write the files to disk. This option is incompatible with watch mode.

Default ​

ts
true

Released under the MIT License.