Lofi Bundler

1.0.1 · active · verified Wed Apr 22

Lofi Bundler is a minimalist TypeScript utility designed for projects that prioritize simplicity and a zero-dependency build process, especially when targeting browser environments or when complex module loaders are unnecessary. It operates by walking through all specified TypeScript files within a project (explicitly excluding `node_modules` and other external folders) and concatenating their content into a single TypeScript bundle. This bundled file can then be fed into the standard TypeScript compiler (`tsc`) for final compilation, eliminating the need for more elaborate bundling solutions like Webpack, Rollup, or even Babel configurations. The package's current stable version is 1.0.1, suggesting a mature, feature-complete state with an infrequent release cadence focused on stability. Its primary differentiator lies in its 'lofi' philosophy: a bare-bones approach that avoids external dependencies and configuration overhead, making it ideal for small, self-contained utilities or libraries that need to run in both Node.js and the browser without introducing complex build chains or module resolution challenges inherent to different environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and run `lofi-bundler` via CLI in `package.json` scripts, including the subsequent `tsc` step for browser compatibility, and also shows programmatic API usage for direct integration.

{
  "name": "my-lofi-project",
  "version": "1.0.0",
  "scripts": {
    "prebuild:browser": "rm -f bundle.ts",
    "build:browser": "lofi-bundler && tsc bundle.ts --target es5 --module commonjs --outFile dist/browser-bundle.js",
    "postbuild:browser": "rm bundle.ts" 
  },
  "config": {
    "lofi-bundler": {
      "entry": "src/index.ts",
      "target": "bundle.ts",
      "include": "src/utils/*.ts" 
    }
  },
  "devDependencies": {
    "lofi-bundler": "^1.0.0",
    "typescript": "^5.0.0"
  }
}

// src/index.ts
export function sayHello(name: string): string {
  return `Hello from Lofi Bundler, ${name}!`;
}

// src/utils/math.ts
export function add(a: number, b: number): number {
  return a + b;
}

// To run:
// 1. Save the above package.json
// 2. Create src/index.ts and src/utils/math.ts with the content above.
// 3. Run `npm install` or `yarn install`.
// 4. Run `npm run build:browser` or `yarn build:browser`.
// This will generate `dist/browser-bundle.js`.

// Example of programmatic usage (optional, does not require package.json config)
// import { traceConcat } from 'lofi-bundler';
// import * as fs from 'fs';

// async function generateBundleApi() {
//   const entryFilePath = 'src/index.ts';
//   const bundledSource = await traceConcat(entryFilePath);
//   fs.writeFileSync('bundle-via-api.ts', bundledSource);
//   console.log('Bundle generated via API to bundle-via-api.ts');
// }
// generateBundleApi();

view raw JSON →