Skip to content

Optimize build time speed with a cache (or other settings) #23392

@polarathene

Description

@polarathene

Describe the feature

Presently Nuxt seems to lack a build cache? (Next has one that can be cached for speeding up builds)

In a real Nuxt project, I am observering nuxt build taking roughly 38 seconds (8s vite client, 11s vite server, 19s nitro server). This does not improve when running nuxt build again, even though nothing has changed.

Is it possible to optimize any of the build steps involved?

  • Do the build tools used support re-use of a cache and Nuxt just needs to expose a setting (or document one) for enabling this support?
  • If not, are there any opportunities to implement this where it'd be worthwhile?

Perhaps you could use BLAKE3 via @noble/hashes as a speedy way to get a checksum on build inputs? (could be an opt-in flag). This is perhaps a naive approach, and depending on overhead may not always help reduce the build time 😅


Reproduction / Comparison

Nuxt example:

# Reproduction environment:
$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash
$ corepack enable

# An example project (possibly too small for measurable difference):
$ npx -y nuxi init --packageManager pnpm --gitInit false .
# Repeat this step, no improvement to build time:
$ time pnpm build

Next.js example:

# Reproduction environment:
$ docker run --rm -it --workdir /reproduction node:20-bookworm-slim bash
$ corepack enable

# An example project:
$ npx -y create-next-app@latest --use-pnpm --example hello-world .
# Repeat this step, 1st build 10s while builds after are 5s:
$ time pnpm build

Related

I've looked through Nuxt and Nitro docs, nothing really stands out cache wise for a CI to optimize reducing future builds with. Ideally a small change (or none at all) should not require the full build time.

Check existing discussions and issues.

First five pages of each for keywords searches of: build time, build speed, build cache:

There is a deployment guide, but not sure if Nuxt has one for minimizing time of production builds.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions