Skip to content
FrontDepth, Home

Mini Bundler

MiddleSenior

Build a small JavaScript bundler: find imports with a real parser, build the module graph, rewrite ES modules into functions and emit one script that runs.

What you will build

You will write a small webpack-like bundler in plain JavaScript. It takes a virtual file system ({ "/src/index.js": "…" }), parses every module with acorn, follows the imports from the entry to build a dependency graph, rewrites import/export into module functions with getter-based exports, and emits one script with a tiny runtime that runs the app.

Then you make circular imports behave the way ES modules do, teach the bundler JSON modules, and bundle a real multi-file app with your own bundler and run it in the preview.

What you will learn

  • Why bundlers find imports with a parser (an AST), not with regular expressions
  • How module resolution and a dependency graph with stable ids work
  • How ESM is rewritten into module functions, and why exports are getters (live bindings)
  • What a bundle runtime does: the module map, require and the module cache
  • How circular imports behave in CommonJS, in ESM and in your bundler
  • How a bundler turns non-JS files such as JSON into modules

Steps

Other hands-on work on the same topics.

Guided tours through the source of real libraries that rely on it.