Bundlex JavaScript Bundler

3.0.4 · active · verified Tue Apr 21

Bundlex is a JavaScript bundler designed for high performance and scalability, offering in-memory bundling of JavaScript, TypeScript, and JSON files. Currently at stable version 3.0.4, it differentiates itself by its focus on speed and the ability to create highly customizable bundling workflows through its `createBundler` API. While a specific release cadence isn't published, the frequent updates to similar tools suggest an active development cycle. Beyond basic bundling, Bundlex includes a built-in listener for file change events, enabling efficient watch-mode development. Its architecture supports custom bundler implementations by allowing users to define their own info extractor and bundler functions, providing flexibility for niche requirements.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic bundling of TypeScript files and how to set up a file change listener using `jsBundler`.

import { jsBundler } from 'bundlex';
import path from 'path';
import fs from 'fs/promises';

// Define temporary files for the demo
const entryFile = path.resolve('./temp-entry.ts');
const depFile = path.resolve('./temp-dependency.ts');

async function runBundlexQuickstart() {
  // Create dummy files for bundling
  await fs.writeFile(depFile, `export const message = "Hello from dependency!";`);
  await fs.writeFile(entryFile, `
    import { message } from './temp-dependency';
    console.log(message);
    console.log("This is the main entry point.");
  `);

  console.log('Starting Bundlex quickstart...');

  try {
    // Set up a listener for file changes
    jsBundler.on('change', (changedPath: string) => {
      console.log(`[Bundlex Watch] Detected change in: ${changedPath}.`);
      console.log('Re-bundling logic would typically go here...');
    });

    // Bundle the entry file
    const bundledContent = await jsBundler(entryFile);

    console.log('\n--- Bundled Output (truncated) ---');
    console.log(bundledContent.slice(0, 500) + '\n...'); // Display first 500 characters

    // Simulate a file change to trigger the listener
    await new Promise(resolve => setTimeout(resolve, 50)); // Small delay
    await fs.appendFile(depFile, `\n// Added content to trigger change on ${Date.now()}`);
    console.log('\nSimulated file change. Check for listener output above.');

  } catch (error) {
    console.error('Bundlex quickstart failed:', error);
  } finally {
    // Clean up temporary files
    await fs.unlink(entryFile).catch(() => {});
    await fs.unlink(depFile).catch(() => {});
    console.log('\nCleaned up temporary files.');
  }
}

runBundlexQuickstart();

view raw JSON →