unpkg-bundler is a client-side JavaScript library (current version 0.0.12) designed for in-browser code transpilation and bundling, with a unique capability to dynamically fetch and load npm packages directly from unpkg.com. It leverages esbuild internally for high-performance bundling and supports both ES modules (ESM) and CommonJS (CJS) syntax, as well as TypeScript and TSX with React code. The library's core differentiator is its ability to operate without filesystem access, making it ideal for browser-based development environments, interactive code editors, or learning platforms that need to execute user-provided code with npm dependencies on the fly. Its release cadence is currently irregular, typical for projects in early development.
npm install unpkg-bundlerVerified import paths — ran on the pinned version, not inferred.
Demonstrates bundling a React component, including automatic fetching of `react` and `react-dom` from `unpkg.com`, and shows how to execute the resulting bundled code in a browser environment.
Review release notes carefully for updates and consider pinning exact versions in production environments to avoid unexpected changes.
Ensure calls to `bundle()` are prefixed with `await` and are contained within an `async` function or a top-level `await` context.
Ensure all input code is provided as a string, and dependencies are resolved via `unpkg.com` or are self-contained within the input string.
Use `const bundle = require('unpkg-bundler/lib/cjs');` for CommonJS environments.Always import `bundle` as a default import: `import bundle from 'unpkg-bundler';`.
Change `import { bundle } from 'unpkg-bundler';` to `import bundle from 'unpkg-bundler';`.Wrap the call to `bundle` in an `async` function, e.g., `const createBundle = async () => { const { code, err } = await bundle(modules); };`.For ESM, use `import bundle from 'unpkg-bundler';`. For CommonJS, use `const bundle = require('unpkg-bundler/lib/cjs');`.No dependency data recorded yet.