
Nuxt
Extend Nuxt and Nitro apps with build-time and runtime lifecycle hooks—from nuxt.config.ts, custom modules, and server plugins—without guessing hook names or timing.
Install
npx skills add https://github.com/antfu/skills --skill nuxtWhat is this skill?
- Build-time hooks in nuxt.config.ts (build:before, pages:extend, components:dirs)
- Module setup patterns with defineNuxtModule and ready/close/modules:done
- Reference table for common build hooks and when they fire
- Nitro/server runtime hook extension alongside Nuxt app lifecycle
- Generated from pinned sources/nuxt SHA for reproducible agent guidance
Adoption & trust: 16.4k installs on skills.sh; 5.2k GitHub stars; 2/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
Canonical shelf is Build because hooks wire framework behavior while you implement pages, modules, and server runtime—not during launch SEO or ops monitoring. Frontend subphase is the primary home for nuxt.config and module setup, while Nitro server hooks still serve the same product build cycle.
Common Questions / FAQ
Is Nuxt safe to install?
skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Nuxt
# Generation Info - **Source:** `sources/nuxt` - **Git SHA:** `c9fed804b9bef362276033b03ca43730c6efa7dc` - **Generated:** 2026-01-28 --- name: lifecycle-hooks description: Nuxt and Nitro hooks for extending build-time and runtime behavior --- # Lifecycle Hooks Nuxt provides hooks to tap into the build process, application lifecycle, and server runtime. ## Build-time Hooks (Nuxt) Used in `nuxt.config.ts` or modules: ### In nuxt.config.ts ```ts // nuxt.config.ts export default defineNuxtConfig({ hooks: { 'build:before': () => { console.log('Build starting...') }, 'pages:extend': (pages) => { // Add custom pages pages.push({ name: 'custom', path: '/custom', file: '~/pages/custom.vue', }) }, 'components:dirs': (dirs) => { // Add component directories dirs.push({ path: '~/extra-components' }) }, }, }) ``` ### In Modules ```ts // modules/my-module.ts export default defineNuxtModule({ setup(options, nuxt) { nuxt.hook('ready', async (nuxt) => { console.log('Nuxt is ready') }) nuxt.hook('close', async (nuxt) => { console.log('Nuxt is closing') }) nuxt.hook('modules:done', () => { console.log('All modules loaded') }) }, }) ``` ### Common Build Hooks | Hook | When | |------|------| | `ready` | Nuxt initialization complete | | `close` | Nuxt is closing | | `modules:done` | All modules installed | | `build:before` | Before build starts | | `build:done` | Build complete | | `pages:extend` | Pages routes resolved | | `components:dirs` | Component dirs being resolved | | `imports:extend` | Auto-imports being resolved | | `nitro:config` | Before Nitro config finalized | | `vite:extend` | Vite context created | | `vite:extendConfig` | Before Vite config finalized | ## App Hooks (Runtime) Used in plugins and composables: ### In Plugins ```ts // plugins/lifecycle.ts export default defineNuxtPlugin((nuxtApp) => { nuxtApp.hook('app:created', (vueApp) => { console.log('Vue app created') }) nuxtApp.hook('app:mounted', (vueApp) => { console.log('App mounted') }) nuxtApp.hook('page:start', () => { console.log('Page navigation starting') }) nuxtApp.hook('page:finish', () => { console.log('Page navigation finished') }) nuxtApp.hook('page:loading:start', () => { console.log('Page loading started') }) nuxtApp.hook('page:loading:end', () => { console.log('Page loading ended') }) }) ``` ### Common App Hooks | Hook | When | |------|------| | `app:created` | Vue app created | | `app:mounted` | Vue app mounted (client only) | | `app:error` | Fatal error occurred | | `page:start` | Page navigation starting | | `page:finish` | Page navigation finished | | `page:loading:start` | Loading indicator should show | | `page:loading:end` | Loading indicator should hide | | `link:prefetch` | Link is being prefetched | ### Using Runtime Hooks ```ts // composables/usePageTracking.ts export function usePageTracking() { const nuxtApp = useNuxtApp() nuxtApp.hook('page:finish', () => { trackPageView(useRoute().path) }) } ``` ## Server Hooks (Nitro) Used in server plugins: ```ts // server/plugins/hooks.ts export default defineNitroPlugin((nitroApp) => { // Modify HTML before sending nitroApp.hooks.hook('render:html', (html, { event }) => { html.head.push('<meta name="custom" content="value">') html.bodyAppend.push('<script>console.log("injected")</script>') }) // Modify response nitroApp.hooks.hook('render:response', (response, { event }) => { console.log('Sending response:', response.statusCode) }) // Before request nitroApp.hooks.hook('request', (event) => { console.log('Request:', event.path) }) // After response nitroApp.hooks.hook('afterResponse', (event) => { console.log('Response sent') }) }) ``` ### Common Nitro Hooks | Hook | When | |------|------| | `request` | Request received | | `beforeResponse` |