Vibe Coding Bundler

1.0.0 · active · verified Tue Apr 21

Vibe Coding Bundler is a browser-based JavaScript and TypeScript bundler that leverages esbuild-wasm to perform compilation entirely within the browser environment, eliminating the need for a server. Currently at version 1.0.0, its release cadence is feature-driven as an initial offering. Key differentiators include first-class support for standard import maps, a virtual file system for in-memory bundling, and a robust plugin system with `onResolve` and `onLoad` hooks. It supports various output formats (ESM, IIFE, CJS), generates sourcemaps, and performs tree shaking. While it transpiles TypeScript and JSX, it does not perform type checking. An optional Node.js CLI is also provided for local development workflows.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up and use the bundler in a browser environment, including initializing esbuild-wasm, providing virtual files, configuring import maps for CDN dependencies like React, and outputting a minified ESM bundle with an inline sourcemap. It also shows how to execute the bundled output.

import { createBundler, initialize } from 'vibe-coding-bundler';

async function runBundler() {
  // Initialize esbuild-wasm (only needed once per application lifetime)
  await initialize();

  // Create a bundler instance with a custom fetcher for external modules
  const bundler = createBundler({
    fetcher: async (url) => {
      // Example: add custom headers or caching logic
      const response = await fetch(url);
      if (!response.ok) {
        throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
      }
      return { contents: await response.text() };
    },
  });

  // Define virtual files and an import map for resolving bare specifiers
  const files = {
    '/src/index.ts': `
      import { useState } from 'react';
      export function App() {
        const [count, setCount] = useState(0);
        return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
      }
      console.log('App loaded');
    `,
  };

  const importMap = {
    imports: {
      react: 'https://esm.sh/react@18',
      'react/': 'https://esm.sh/react@18/' // Important for subpaths
    },
  };

  // Bundle the code
  const result = await bundler.bundle(
    '/src/index.ts', // Entry point
    files,           // Virtual file system
    importMap,       // Import map configuration
    {
      format: 'esm',
      minify: true,
      sourcemap: 'inline',
      target: 'es2020'
    }
  );

  // Log the bundled output (typically a single output file 'index.js')
  console.log(result.outputFiles['index.js']);

  // Example: Run the bundled code in a browser context
  const script = document.createElement('script');
  script.type = 'module';
  script.textContent = result.outputFiles['index.js'];
  document.body.appendChild(script);
}

runBundler().catch(console.error);

view raw JSON →