๐Ÿ“ฆ pi0 / nuxt-build-cache

โ–ฃ Speed up your Nuxt builds up to 2x [experimental]

โ˜… 154 stars โ‘‚ 1 forks ๐Ÿ‘ 154 watching
๐Ÿ“ฅ Clone https://github.com/pi0/nuxt-build-cache.git
HTTPS git clone https://github.com/pi0/nuxt-build-cache.git
SSH git clone git@github.com:pi0/nuxt-build-cache.git
CLI gh repo clone pi0/nuxt-build-cache
Pooya Parsa Pooya Parsa chore: fix description d77afa9 2 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ playground
๐Ÿ“ src
๐Ÿ“„ .editorconfig
๐Ÿ“„ .eslintignore
๐Ÿ“„ .eslintrc
๐Ÿ“„ .gitignore
๐Ÿ“„ .npmrc
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ package.json
๐Ÿ“„ pnpm-lock.yaml
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

โ–ฃ Nuxt Build Cache

[!IMPORTANT]
This is a highly experimental project. Use at your own risk in production!

โœจ Quick Start

npx nuxi module add nuxt-build-cache

๐Ÿ’ก What does it do?

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.

How does the module determine if a new build is required?

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):

  • Loaded config
  • Files in known Nuxt directories (pages/, layouts/, app.vue, ...)
  • Known project root files (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 in nuxt.config (like an environment variable), it will be used as a source for your build hashes ๐Ÿ‘

โš™๏ธ Environment variables

  • NUXT_DISABLE_BUILD_CACHE: Disable the module entirely
  • NUXT_IGNORE_BUILD_CACHE: Skip restoring cache even if it exists