[!IMPORTANT] This is a highly experimental project. Use at your own risk in production!
npx nuxi module add nuxt-build-cache
By enabling this module, after a nuxt build
, Nuxt collects build artifacts from .nuxt/
dir into a tar file. On subsequent builds, if none of the relevant dependencies or your codes change, Nuxt will avoid the Vite/Webpack build step and simply restore the previous build results.
This is particularly useful to speed up the CI/CD process when only prerendered content (from a CMS for example) or server routes are changed and can significantly speed up build speeds (up to 2x!). This is a similar feature we introduced in Nuxt 2.
We generate a hash of the current state during the build from various sources using unjs/ohash and then use this hash to store the build artifacts. (By default in node_modules/.cache/nuxt/build/{hash}/
). This way each cache is unique to the project state it was built from.
The hash is generated from your code and all Nuxt layers (that are not in node_modules
):
pages/
, layouts/
, app.vue
, ...)package.json
, .nuxtrc
, .npmrc
, package manager lock-file, ...)[!NOTE] File hashes are based on their size and content digest (murmurHash v3)
[!IMPORTANT] Config layer hashes will be generated from the loaded value. If you have a config like
{ date: new Date() }
, the cache will not work! But if you update a runtime value innuxt.config
(like an environment variable), it will be used as a source for your build hashes 👍
NUXT_DISABLE_BUILD_CACHE
: Disable the module entirelyNUXT_IGNORE_BUILD_CACHE
: Skip restoring cache even if it exists