Parcel Bundler

2.16.4 · active · verified Tue Apr 21

Parcel is a blazing fast, zero-configuration web application bundler designed for simplicity and performance. The current stable version is 2.16.4, with the project maintaining a frequent release cadence for minor and patch updates. Key differentiators include its 'zero-config' approach, aiming to get developers up and running quickly without extensive setup. Under the hood, Parcel leverages Rust-based tooling (such as its JavaScript compiler and HTML/SVG transformers since v2.15.0) for significant performance improvements in bundling, minification, and tree-shaking. It supports a wide range of web assets out-of-the-box, including JavaScript (ES modules, CommonJS), TypeScript, React Server Components (since v2.14.0), CSS, HTML, SVG, images, and more, with automatic code splitting and differential bundling. Parcel also offers a robust plugin system for extensibility and a programmatic API for custom build integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates programmatically building a project with Parcel using its JavaScript API, including setup for a worker farm and in-memory file system. It configures a production build for an HTML entry point and logs the build time and a snippet of the output HTML.

import { Parcel } from '@parcel/core';
import { createWorkerFarm } from '@parcel/core';
import defaultConfig from '@parcel/config-default';
import { MemoryFS } from '@parcel/fs';

// Create a worker farm for multi-threading, essential for Parcel's performance.
const workerFarm = createWorkerFarm();

async function buildProject() {
  // Create an in-memory file system for output, useful for testing or server-side rendering.
  const outputFS = new MemoryFS(workerFarm);

  const bundler = new Parcel({
    entries: ['./src/index.html'], // Your main entry point
    defaultConfig,
    workerFarm,
    outputFS,
    mode: 'production', // Build for production, enabling minification and tree-shaking
    defaultTargetOptions: {
      shouldOptimize: true,
      sourceMaps: false,
      engines: { node: '>= 16.0.0' }, // Ensure Node.js version is specified
    },
  });

  try {
    const { bundleGraph, buildTime } = await bundler.run();
    console.log(`✨ Built in ${buildTime}ms`);
    // You can access bundles from bundleGraph and read them from outputFS
    const htmlBundle = Array.from(bundleGraph.get === 'html')[0];
    if (htmlBundle) {
      const content = await outputFS.readFile(htmlBundle.filePath, 'utf8');
      console.log('Output HTML content sample:\n', content.substring(0, 500));
    }
  } catch (error) {
    console.error('❌ Build failed:', error);
    process.exit(1);
  } finally {
    await workerFarm.end(); // Clean up worker processes
  }
}

buildProject();

view raw JSON →