Skip to content

Build Options ​

Configure in tspub.config.ts:

typescript
export default {
  build: {
    entry: "src/index.ts",
    formats: ["esm", "cjs"],
    outDir: "dist",
    dts: true,
    sourcemap: true,
    clean: true,
  },
};

Reference ​

OptionTypeDefaultDescription
entrystring | string[] | Record<string, string>auto-detectedEntry point(s)
formats("esm" | "cjs" | "iife")[]["esm"]Output formats
outDirstring"dist"Output directory
dtsbooleantrueGenerate .d.ts files
dtsBundlebooleanfalseBundle .d.ts files into single-file declarations per entry
dtsResolvebooleanfalseResolve external package types into bundled .d.ts
sourcemapbooleanfalseGenerate sourcemaps
cleanbooleantrueClean outDir before build
minifybooleanfalseMinify output
splittingbooleanfalseEnable code splitting (ESM only, auto-enabled for multi-entry)
targetstring—esbuild target (e.g. "es2022", "node18")
platform"node" | "browser" | "neutral"—Target platform
external(string | RegExp)[]—Packages to exclude from bundle
noExternalstring[]—Force-bundle specific packages
defineRecord<string, string>—Compile-time constants
banner{ js?: string }—Prepend text to output files
footer{ js?: string }—Append text to output files
cjsInteropbooleantrueEnable CJS interop (consumers don't need .default)
esbuildPluginsPlugin[]—Pass esbuild plugins directly
loaderRecord<string, Loader>—Custom esbuild loaders by extension
replaceNodeEnvboolean—Replace process.env.NODE_ENV (auto-enabled when minify is true)
globalNamestring—Global variable name for IIFE builds
onSuccessstring | () => void—Run a command or callback after successful build
treeshakeboolean | { ignoreAnnotations?: boolean }—Esbuild treeshake configuration
publicDirstring—Copy static assets from this directory to outDir
injectstring[]—Files to inject into all bundles
sizeLimitsRecord<string, string>—Size budget limits — fail build if any file exceeds the limit
shimsbooleantrueInject __dirname/__filename/import.meta.url shims into CJS output

Released under the MIT License.