
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
ts-project-builder
Advanced tools
Rollup-based TypeScript builder with multi-format output and built-in common plugins.
Rollup-based TypeScript builder with multi-format output and built-in common plugins.
>= 18.12.1Using pnpm:
pnpm add -D ts-project-builder
You can also use yarn, npm, or bun.
Use the -h flag to view usage and all available options:
ts-project-builder -h # from package.json script
npx ts-project-builder -h # directly from terminal
Run the builder with a single entry file:
ts-project-builder ./src/index.ts
By default, it outputs both CommonJS (.cjs) and ESM (.mjs) formats to the ./dist directory.
You can pass multiple inputs and specify desired output formats:
# Output as amd, cjs, and esm
ts-project-builder ./src/cli.ts ./src/index.ts -f amd,cjs,esm
# Use glob patterns (wrap in quotes!)
ts-project-builder './src/**/*.ts' -f cjs
[!IMPORTANT] Input files must be listed before any flags to ensure correct parsing.
Each format will generate files with the following extensions:
| Format | Extension |
|---|---|
| amd | amd.js |
| cjs | cjs |
| commonjs | cjs |
| es | mjs |
| esm | mjs |
| iife | iife.js |
| module | mjs |
| system | system.js |
| systemjs | system.js |
| umd | umd.js |
This builder uses the following Rollup input plugins (in order):
For more options and advanced configuration, see the CLI Flags section.
--cleanCleans the output directory or files right before writing output files.
If used without a value, all formats will be cleaned.
If specific formats are provided, only output files for the specified formats will be cleaned.
If the build fails, nothing will be cleaned.
Files or folders to be cleaned are determined by their output paths.
👉 If multiple formats (e.g. CJS and ESM) share the same output directory (like ./dist), using --clean cjs will still clean the entire directory.
# Clean all formats before output
ts-project-builder ./src/index.ts --clean
# Clean only CJS format before output
ts-project-builder ./src/index.ts --clean cjs
[!IMPORTANT] An error will be thrown if the path to be cleaned is outside the current working directory.
To bypass this check, use
--force-clean.
-c, --configSpecifies the path to the config file.
Only .mjs files are supported — the file must be an ES module, as it is loaded using await import.
Default: ./ts-project-builder.config.mjs
--force-cleanForcibly cleans the target directory or files before output, even if they are outside the current working directory.
[!CAUTION]
Use this flag with caution — it can delete files outside your project folder.
-f, --formatsSpecifies the output formats.
Multiple formats can be provided, separated by commas. Duplicate entries will be ignored.
Default: cjs,esm
-m, --minifyMinifies the output using the minify option from rollup-plugin-esbuild.
--clean.--out-dirsSpecifies the output directory path(s).
See Rollup's output.dir documentation for more details.
Default: ./dist
You can define separate output directories for different formats using <format>=<path>, separated by commas.
./dist), it will be used for all formats.# All formats output to ./dist
ts-project-builder ./src/index.ts --out-dirs ./dist
# CJS outputs to ./cjs, all others use default ./dist
ts-project-builder ./src/index.ts --out-dirs cjs=./cjs
# ESM outputs to ./dist, all others to ./output
ts-project-builder ./src/index.ts --out-dirs ./output,esm=./dist
--out-extsSpecifies the output file extensions for each format.
--out-dirs, using <format>=<ext> and separating multiple values with commas.# CJS uses `.cjs`, others use `.js`
ts-project-builder ./src/index.ts --out-exts cjs=cjs,js
# ESM uses `.js`, others use default extensions from the format table
ts-project-builder ./src/index.ts --out-exts esm=js
--out-filesSpecifies exact output file paths.
See the Rollup documentation for more details.
--out-dirs flag.--out-dirs, using <format>=<path>.# CJS outputs to ./cjs.cjs, all other formats use ./dist
ts-project-builder ./src/index.ts --out-files cjs=./cjs.cjs
# - CJS outputs to ./cjs/index.cjs (from --out-files)
# - ESM outputs to ./esm (from --out-dirs)
# - All others output to ./dist (default)
ts-project-builder ./src/index.ts --out-dirs cjs=./cjs-dist,esm=./esm --out-files cjs=./cjs/index.cjs
--preserve-modulesPreserves the module structure in the output (i.e., does not bundle into a single file).
See Rollup documentation for details.
--clean.--preserve-modules-rootsSpecifies the root directory for preserved modules.
See Rollup documentation for details.
./src--out-dirs.--sourcemapsEnables or configures sourcemap output.
See the Rollup documentation for more details.
true, false, inline, and hidden.--out-dirs.# All formats use the 'true' setting (sourcemaps enabled)
ts-project-builder ./src/index.ts --sourcemaps
# ESM format uses 'inline', all others use 'false' (sourcemaps disabled)
ts-project-builder ./src/index.ts --sourcemaps false,esm=inline
# Only disable sourcemaps for the ESM format
ts-project-builder ./src/index.ts --sourcemaps esm=false
If you need to customize plugin behavior, modify per-format output, or access advanced options, you can use a configuration file.
By default, the builder looks for ./ts-project-builder.config.mjs.
You can override this using the -c flag.
Create a config file and start with the following template:
import { defineConfig } from 'ts-project-builder';
export default defineConfig({});
For full type definitions and configuration options, refer to the Config interface in ./src/types.ts.
You can also use ts-project-builder as a library by directly importing the Builder class.
Create a builder instance and call the build() method:
import { Builder } from 'ts-project-builder';
const builder = new Builder({
inputs: ['./src/index.ts'],
output: {
formats: new Set([
'cjs',
'esm'
]),
},
});
await builder.build();
FAQs
Rollup-based TypeScript builder with multi-format output and built-in common plugins.
The npm package ts-project-builder receives a total of 88 weekly downloads. As such, ts-project-builder popularity was classified as not popular.
We found that ts-project-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.