server assets: support non-embedded mode for large asset sets

Open
#5,078 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
bun, deno, node.js, rollup, typescript

Research direction

Start with src/build/virtual/server-assets.ts and the v2 implementation in #4507 to understand the existing asset modes. Compare the filesystem copy and runtime readFile path with the single-module inline option, including how presets without a filesystem retain embedded assets. Done means large asset sets can build without embedding every file on supported presets while the default still works for workers and edge presets.

Written by the indexing model from the issue text.

Description

assets performance

Tracker for large server asset sets, picked up from #1833 (closed on v2).

In production builds, every file under server/assets becomes its own Rollup module through raw: (src/build/virtual/server-assets.ts). Each file is read into memory as a string and emitted as export default "<content>", and the bundler holds the source, rendered chunk and output of every module until it writes. In #1833, 3,500 JSON files of ~300 KB each (~1 GB) ran out of heap during the build. Building also gets slow from about 1,000 files.

Main embeds assets the same way, so v3 has the same limit. Fixing it needs a mode that doesn't embed every file, for example:

  • embed: false: copy the files into the server output, bake the metadata at build time, and readFile at runtime. Only works on presets that have a filesystem (node, bun, deno).
  • embed: "inline": one virtual module for all assets instead of N raw: chunks. Faster, but still holds everything in memory.

#4507 implemented both as opt-in modes on v2 and is a reasonable starting point. Embedding should stay the default for presets without a filesystem (workers, edge).

The "too many open files" error from the same report was already fixed in #2458.

Opened with AI assistance.

Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.