TypeScript Project Bundler

0.0.12 · abandoned · verified Tue Apr 21

ts-project-bundle is an experimental command-line interface (CLI) tool designed to simplify the bundling of TypeScript projects that leverage TypeScript's project references feature. Versioned at 0.0.12 and explicitly marked as a "prototype," it offers a basic mechanism to combine a main TypeScript project and its declared library dependencies into a single output directory, preserving their relative folder structure. Unlike full-featured bundlers such as Webpack or Rollup, ts-project-bundle focuses on the compilation and file restructuring aspects, relying on `tsc --build` for the initial compilation phase. Its primary differentiator is its direct integration with TypeScript project references, aiming to provide a lightweight solution for consolidating compiled output, particularly useful in monorepo environments where multiple interdependent TypeScript packages need to be deployed together. The tool's development appears to have ceased, with no significant updates since late 2022, indicating an abandoned status.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and run `ts-project-bundle` on a minimal TypeScript project leveraging project references, compiling and consolidating its output into a single directory structure.

# Assume current working directory is a monorepo root: ~/my-monorepo
# This quickstart demonstrates creating a simple monorepo with two TypeScript packages,
# 'common' and 'api', where 'api' depends on 'common' via project references.

# 1. Create dummy package 'common'
mkdir -p packages/common/src
echo 'export const getGreeting = (name: string) => `Hello, ${name}!`;' > packages/common/src/index.ts
echo '{ "compilerOptions": { "outDir": "dist", "rootDir": "src", "target": "es2020", "module": "commonjs", "strict": true }, "include": ["src"] }' > packages/common/tsconfig.json
cd packages/common
npm init -y # Initialize common package
cd ../.. # Back to monorepo root

# 2. Create dummy package 'api' that depends on 'common'
mkdir -p packages/api/src
echo 'import { getGreeting } from "@myorg/common"; console.log(getGreeting("World"));' > packages/api/src/index.ts
echo '{ "compilerOptions": { "outDir": "dist", "rootDir": "src", "target": "es2020", "module": "commonjs", "strict": true, "baseUrl": ".", "paths": { "@myorg/common": ["../common/src"] } }, "references": [{ "path": "../common" }], "include": ["src"] }' > packages/api/tsconfig.json
cd packages/api
npm init -y # Initialize api package
npm install --save-dev ts-project-bundle typescript # Install ts-project-bundle and TS locally

# 3. Crucial: Compile the project and its references using tsc --build
npx tsc --build

# 4. Run ts-project-bundle from the 'api' package
# --root points to the monorepo root (where 'packages' is)
# --project points to the current 'api' directory
# --out specifies the output folder relative to the project (api)
npx ts-project-bundle --root=../../ --project=. --out=./out-bundle

echo "\nCheck the 'packages/api/out-bundle' directory for the bundled output."

view raw JSON →