nuxt-prepare
Build actions for Nuxt
49,525
104
| Install | |
|---|---|
npm install nuxt-prepare |
|
| Latest Version: | 4.0.0 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Aug 8, 2026 |
| Links: | GitHub · npm |
Maintainer: johannschopplich
Nuxt Prepare
Nuxt module to run async initialization steps at build-time.
Features
- 🦦 Zero-Config
- 🦎 Run sync or async operations when Nuxt builds your app
- ✂️ Conditionally overwrite runtime config or app config values
- 🍡 Run scripts in series or parallel
- 🥢 Ready for Nitro server routes
- 🦾 Better DX with
defineNuxtPrepareHandler
Setup
npx nuxt module add prepare
Basic Usage
Add Nuxt Prepare to your Nuxt configuration:
// `nuxt.config.ts`
export default defineNuxtConfig({
modules: ['nuxt-prepare']
})
By default, Nuxt Prepare will look for a server.prepare.ts file in your project root. To run synchronous or asynchronous code when Nuxt builds your app, define a handler in your project root and export a default function:
// `server.prepare.ts`
import { defineNuxtPrepareHandler } from 'nuxt-prepare/config'
export default defineNuxtPrepareHandler(async () => {
// Do some async magic here, e.g. fetch data from an API
return {
// Overwrite the runtime config variable `foo`
runtimeConfig: {
public: {
foo: 'Overwritten by "server.prepare" script'
}
},
// Pass custom state to Nuxt and import it
// anywhere from `#nuxt-prepare`
state: {
foo: 'bar'
}
}
})
[!TIP] You can run as many prepare scripts as you want – add them to the
prepare.scriptsmodule configuration.
The documentation covers the handler API, prepare state and every module option.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run
pnpm run dev:prepare - Start development server using
pnpm run dev
Credits
- Konkon for his logo pixel art.
- McPizza0 for his inspirational
nuxt-server-initmodule.
License
MIT License © 2023-PRESENT Johann Schopplich
Related Packages
nuxt-define
One utility function for module authors to define compiler constants for all bui...
13,412,511
Version History
| Version | Released | License |
|---|---|---|
| 4.0.0 | MIT | |
| 3.1.0 | MIT | |
| 3.0.0 | MIT | |
| 2.3.2 | MIT | |
| 2.3.1 | MIT | |
| 2.3.0 | MIT | |
| 2.2.0 | MIT | |
| 2.1.1 | MIT | |
| 2.1.0 | MIT | |
| 2.0.1 | MIT | |
| 2.0.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.0 | MIT | |
| 0.3.0 | MIT | |
| 0.2.2 | MIT | |
| 0.2.1 | MIT | |
| 0.1.2 | MIT | |
| 0.1.1 | MIT | |
| 0.1.0 | MIT |
