From my notes

Nuxt under the hood

Questions and flashcards from your Nuxt internals note — carrying values from build time to runtime, the start-up sequence from config loading to the bundles, module order and modules:done, config priority across layers, Nitro and h3, why h3 instead of Express, how a request reaches the Vue renderer, and deployment presets.

Written from your under the hood note, the untitled one about the build and runtime worlds, the start-up sequence and Nitro. The matching study section is Under the hood.

Know

  • Two worlds: build-time code and runtime code are different programs, so values are carried over deliberately.
  • Start-up: config loading and merging, schema resolution, the Nuxt instance, modules in order, app resolution, the builds, and the hooks at each step.
  • Server: what h3 and Nitro each do, why h3 runs everywhere, the order in which a request is matched, and presets.

Fact check of your notes

Nothing in this note contradicts the documentation. Two points worth adding to it:

Gotcha· Modules see only what came before them

"I only have access to what the modules before set up" is right, and it is why cross-module work goes into hooks that run later, such as modules:done or components:extend.

Gotcha· Server routes win over pages

Because h3 matches server/ routes before the Vue renderer's catch-all, a server route and a page at the same path never both run: the server route answers.

Exercise

Exercise
  • In a local module, log in setup() and in a modules:done hook how many components are registered, with one more module installed after yours.
  • Add server/routes/about.get.ts next to a pages/about.vue and see which one answers.

Be able to say

Be able to say· What happens when Nuxt starts?

"It loads the config with c12: resolves layers from extends, loads .env, applies environment overrides and merges everything with defu, project first. The result is resolved against Nuxt's schema. Then the hookable Nuxt instance is created and modules are installed in order, internal ones first; each can change options and register hooks, but only sees what earlier modules did, so cross-module work goes into modules:done. Then the app is resolved (plugins, layouts, middleware, pages), templates are generated into .nuxt, Vite builds the client and server bundles, and Nitro bundles the server for its preset."

Be able to say· What are Nitro and h3?

"h3 is a small HTTP framework built on web standards: event handlers, routing and helpers for requests and responses, so the same code runs on Node, edge workers and serverless. Nitro is the server toolkit around it: it scans server/ for routes, middleware and plugins, adds storage, caching and tasks, and bundles everything for a deployment preset. In Nuxt, a request first goes through the server routes, and anything unmatched falls through to the Vue SSR renderer."

Your notes

Open in Notes

Nothing yet. Notes filed here show up on this page and the section overview.