-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
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
:
- Disabling GZIP in builds for some gain (
sourcemaps
is another potential option): docs:nuxt build
- Better document disabling GZIP report #23352 (comment) - 4 minute build times: Is a 4 minute build time normal for larger Nuxt v3 projects? #20642
- 6 minute build times: The packaging time is too slow, up to 6 minutes. Serious impact on development efficiency #20494
- 10 minute report, with 1 minute if disabling SSR: slow windows build #20042
- 80s to 5-10s report if using
experimental.treeshakeClientOnly: false
: slow windows build #20042 (comment) - A report of Nuxt spending half build time in nitro, but nitro direct being fast: slow windows build #20042 (comment)
- A suggestion that upcoming Rollup 4.0 release adopting the rust-based SWC may bring improvements: slow windows build #20042 (comment)
- Associated Rollup 4 PR: [v4.0] Switch parser to SWC and introduce native/WASM code rollup/rollup#5073
- Rollup 4 release tracking PR: [v4.0 release branch] rollup/rollup#5140
- Mar 2019 Nuxt 2 doc links for several build config options to optimize build time (all settings tied to webpack): Increase the Build Speed #5131 (comment)
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
- Read the contribution guide.
- Check existing discussions and issues.