TSBunch: TypeScript Bundler (TS to TS)

0.4.25 · active · verified Tue Apr 21

TSBunch is a specialized TypeScript bundler designed to concatenate multiple `.ts` modules into a single `.ts` file without transpiling them to JavaScript. It is currently at version 0.4.25. Its primary use case is for platforms like CodinGame that require a single-file submission for TypeScript projects but do not allow or need JavaScript transpilation. Unlike mainstream bundlers (e.g., Webpack, Rollup, esbuild), TSBunch avoids generating JavaScript, instead leveraging TypeScript's `namespace` feature for module aggregation. This makes it unique for specific build workflows where the output must remain TypeScript. It has known limitations regarding full ES module import/export syntax support and does not resolve circular dependencies, operating primarily via string matching rather than a full AST analysis.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use the `tsbunch` function to bundle a TypeScript entry file, specify an output path, and include an optional declaration file, illustrating its core command-line usage.

import tsbunch from 'tsbunch';
import path from 'path';

// Simulate an entry file
// tsbunch expects actual files on disk
// For a runnable example, create these files first:
// 
// // src/moduleA.ts
// export const dataA = 'Hello from Module A!';
// 
// // src/entry.ts
// import { dataA } from './moduleA';
// namespace MyBundle {
//   console.log(dataA);
//   export const bundledMessage = `Bundled: ${dataA}`;
// }
// 
// // src/declarations.d.ts
// declare namespace Global {
//   const APP_VERSION: string;
// }

const entryFile = path.resolve(__dirname, 'src/entry.ts');
const outputFile = path.resolve(__dirname, 'out/bundle.ts');
const declarationFile = path.resolve(__dirname, 'src/declarations.d.ts');

// In a real scenario, you'd ensure 'src' and 'out' directories exist.
// For demonstration, we'll just show the call.

try {
  console.log('Attempting to bundle...');
  tsbunch(entryFile, outputFile, declarationFile);
  console.log(`Bundle created successfully at ${outputFile}`);
  console.log('You would typically inspect ' + outputFile + ' now.');
  console.log('Note: This code snippet assumes you have actual files for entry, output, and declarations.');
} catch (error) {
  console.error('Bundling failed:', error);
  console.error('Make sure your entry, output, and declaration file paths are correct and the files exist.');
}

// To run this: 
// 1. Create the files: src/moduleA.ts, src/entry.ts, src/declarations.d.ts
// 2. Install tsbunch: npm install --save-dev tsbunch
// 3. Run: node your-quickstart-file.js

view raw JSON →