Skip Navigation code drift

How Vercel Gets Their Bundles Small

written  &  updated
in TIL, but also Code, JavaScript, & Tools

The @vercel/nft (Node File Trace) package is responsible for a lot of Vercel's bundling magic. It statically analyzes files and can find non-JS dependencies in the execution path by spotting filesystem intersections via readFile and readStream calls.

The result of this call is a list of only the files & directories you really needed to include in a given serverless lambda or edge function. It only deals in userland code, meaning a heavy node_modules import can still push you over the 50MB runtime limit if you're trying to run something like Puppeteer on the edge.

This may eventually move to turbotrace, which is marked as experimental in the Next docs, but its unlikely to be anything other than a static analysis tool. That means a lot of the current nft bugs are also likely to exist or require retesting in turbotrace.