Advanced

Tree Shaking & Bundle Size

Rezo is structured for aggressive tree-shaking. Instead of importing the entire library, you can import only the adapter, platform, or module you need. This keeps your bundle small — especially important for browser and edge deployments.

The Problem

The default import includes the HTTP adapter and all core utilities:

import rezo from 'rezo';
// Pulls in: HTTP adapter, all utilities, all types, cookie jar, etc.

For a Node.js server, this is fine. For a browser bundle or edge worker, you’re shipping unused code.

Per-Adapter Imports

Import only the adapter you need. Each adapter export provides the Rezo class preconfigured with that adapter:

// HTTP adapter (Node.js native http/https)
import { Rezo } from 'rezo/adapters/http';

// HTTP/2 adapter (Node.js native http2)
import { Rezo } from 'rezo/adapters/http2';

// Fetch adapter (universal fetch API)
import { Rezo } from 'rezo/adapters/fetch';

// XHR adapter (XMLHttpRequest for browsers)
import { Rezo } from 'rezo/adapters/xhr';

// cURL adapter (shell exec)
import { Rezo } from 'rezo/adapters/curl';

// React Native adapter
import { Rezo } from 'rezo/adapters/react-native';

Each import gives you a Rezo class that uses only that adapter. The other adapters are excluded from the bundle.

Example: Browser with Fetch Only

import { Rezo } from 'rezo/adapters/fetch';

const client = new Rezo({
  baseURL: 'https://api.example.com',
  timeout: 10000,
});

const { data } = await client.get('/users');

This import does not include the Node.js http, http2, net, tls, or zlib modules, keeping the bundle browser-compatible and small.

Per-Platform Imports

Platform entries are preconfigured with the right adapter and export a default instance:

// Node.js
import rezo from 'rezo/platform/node';

// Bun
import rezo from 'rezo/platform/bun';

// Deno
import rezo from 'rezo/platform/deno';

// Browser
import rezo from 'rezo/platform/browser';

// React Native
import rezo from 'rezo/platform/react-native';

// Edge workers (Cloudflare, Vercel, etc.)
import rezo from 'rezo/platform/worker';

See Platform Entries for full details on what each platform provides.

Module-Level Subpath Imports

Larger subsystems are available as separate subpath exports:

rezo/wget — Site Cloning

import { Wget, AssetExtractor, UrlFilter } from 'rezo/wget';

Includes the full wget module: Downloader, AssetExtractor, AssetOrganizer, LinkConverter, StyleExtractor, UrlFilter, and all associated types.

rezo/crawler — Web Crawler

import { Crawler } from 'rezo/crawler';

The web crawler module for structured data extraction.

rezo/dom — DOM Parsing

import { parseHTML, DOMParser } from 'rezo/dom';

Lightweight DOM parsing (uses linkedom internally) for server-side HTML processing.

ESM + CJS Dual Output

Rezo ships both ESM and CommonJS builds:

FormatEntry PointExtension
ESMdist/index.js.js
CJSdist/index.cjs.cjs

Modern bundlers (Vite, esbuild, webpack 5, Rollup) automatically select the ESM build for tree-shaking. Node.js with "type": "module" uses ESM natively.

package.json Exports

The exports field in package.json maps subpath imports to the correct files for both ESM and CJS consumers:

{
  "exports": {
    ".": {
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    },
    "./platform/node": {
      "import": "./dist/platform/node.js",
      "require": "./dist/platform/node.cjs"
    },
    "./adapters/fetch": {
      "import": "./dist/adapters/entries/fetch.js",
      "require": "./dist/adapters/entries/fetch.cjs"
    }
    // ... etc
  }
}

Bundle Size Strategy

Minimal Browser Bundle

For the smallest possible browser bundle:

// Only the Fetch adapter + core Rezo class
import { Rezo } from 'rezo/adapters/fetch';

const client = new Rezo({ baseURL: 'https://api.example.com' });

Excludes: HTTP adapter, HTTP/2, cURL, XHR, wget, crawler, DOM, stealth, proxies, cookies, compression, Node.js builtins.

API Client

For a typical API client in Node.js:

import rezo from 'rezo/platform/node';

Includes: HTTP adapter, cookies, headers, form-data, error handling. Excludes: HTTP/2, wget, crawler, DOM, stealth, cURL, XHR, React Native.

For a scraping or automation server that needs everything:

import rezo from 'rezo';
import { Rezo as Http2Rezo } from 'rezo/adapters/http2';
import { Wget } from 'rezo/wget';
import { Crawler } from 'rezo/crawler';

What Gets Tree-Shaken

ImportIncludedExcluded
rezo/adapters/fetchFetch adapter, core Rezo, typesHTTP, HTTP/2, cURL, XHR, RN
rezo/platform/browserFetch adapter, cookies, headers, form-dataNode.js modules, server features
rezo/platform/nodeHTTP adapter, all utilsOther adapters
rezoHTTP adapter, all utils, all typesOther adapters

Import Best Practices

  1. Choose your platform entry for applications with a known runtime:

    import rezo from 'rezo/platform/node';
  2. Choose a specific adapter for libraries that need to work across runtimes:

    import { Rezo } from 'rezo/adapters/fetch';
  3. Import utilities individually when you only need specific tools:

    import { toCurl, fromCurl } from 'rezo';
    import { RezoHeaders } from 'rezo';
  4. Import subsystems separately when using optional features:

    import { Wget } from 'rezo/wget';
    import { Crawler } from 'rezo/crawler';
  5. Avoid the default import in browser bundles unless your bundler handles tree-shaking well:

    // Prefer this in browsers:
    import rezo from 'rezo/platform/browser';
    
    // Instead of:
    import rezo from 'rezo';