Bit Bundler Browserpack

4.0.2 · active · verified Sun Apr 19

bit-bundler-browserpack is a plugin for the bit-bundler asset bundling system, specifically designed for processing and packaging JavaScript assets. It leverages the robust browser-pack library as its core bundle generator, enabling bit-bundler to create browser-compatible JavaScript bundles. The package is currently at version 4.0.2 and serves as a primary mechanism for bit-bundler to handle JavaScript modules, supporting features like inline source map generation and UMD (Universal Module Definition) exports for broad environment compatibility (Node.js, RequireJS, traditional script tags). While it offers options to fine-tune browser-pack directly, it generally automates most configurations, ensuring seamless integration. Its release cadence is closely tied to bit-bundler's development, providing stability and compatibility within that ecosystem. It differentiates itself by providing a browser-pack powered backend within the bit-bundler framework, offering a tailored bundling solution for JavaScript source files.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and use bit-bundler-browserpack as the JavaScript bundler within a bit-bundler project, enabling source maps and UMD output.

import Bitbundler from 'bit-bundler';
import path from 'path';

// This example assumes 'src/index.js' and 'src/utils.js' exist.
// E.g., src/index.js: `import { greet } from './utils'; greet('World');`
// E.g., src/utils.js: `export function greet(name) { console.log(`Hello, ${name}!`); }`

async function createJavaScriptBundle() {
  const bundler = new Bitbundler({
    src: 'src/index.js', // Your application's entry point
    dest: 'dist/bundle.js', // Output bundle path
    // Specify bit-bundler-browserpack as the bundler provider
    // and pass configuration options to it.
    bundler: ['bit-bundler-browserpack', {
      sourceMap: true, // Generate inline source maps for easier debugging
      umd: 'myAwesomeApp', // Export as a UMD module accessible as 'myAwesomeApp'
      printInfo: true    // Log basic module information during bundling
    }],
    // Additional Bit-bundler configurations, e.g., for module resolution
    resolve: {
      modules: ['node_modules', 'src'] // Resolve modules from node_modules and your 'src' directory
    }
  });

  try {
    const result = await bundler.bundle();
    console.log(`Bundle successfully created at ${result.dest}`);
    // You can now use 'node dist/bundle.js' or include it in a <script> tag.
  } catch (error) {
    console.error('Failed to create bundle:', error);
    process.exit(1);
  }
}

createJavaScriptBundle();

view raw JSON →