Nuxt 4 Overview
Nuxt 4 is a major update incorporating the latest Vue 3 ecosystem technologies. It features faster startup, improved DX, and a new directory structure.
New Directory Structure
project/
├── app/
│ ├── components/
│ ├── composables/
│ ├── layouts/
│ ├── pages/
│ ├── plugins/
│ └── app.vue
├── public/
├── server/
│ ├── api/
│ ├── middleware/
│ └── plugins/
├── nuxt.config.ts
└── package.json
Change: Application code has moved to the
app/directory, clearly separating it from server code.
Performance Improvements
Startup Time Reduction
Dev server startup:
- Nuxt 3: 2.5s
- Nuxt 4: 1.2s (52% faster)
Hot reload:
- Nuxt 3: 300ms
- Nuxt 4: 100ms (66% faster)
Build Optimization
// nuxt.config.ts
export default defineNuxtConfig({
future: {
compatibilityVersion: 4
},
experimental: {
// New optimization options
sharedPrerenderData: true,
compileTemplate: true
}
});
New Data Fetching
Improved useAsyncData
useFetch Type Safety
Server-Side Improvements
Nitro 3 Integration
// server/api/users.ts
export default defineEventHandler(async (event) => {
// H3 new features
const query = getQuery(event);
const body = await readBody(event);
// Validation
const schema = z.object({
name: z.string()
});
const validated = await readValidatedBody(event, schema.parse);
return { users: [] };
});
Server Components
New Composables
usePreviewMode
useLoadingIndicator
Enhanced Layers
// nuxt.config.ts
export default defineNuxtConfig({
extends: [
'@my-org/ui-layer',
'@my-org/auth-layer',
'../shared-config'
]
});
my-app/
├── layers/
│ ├── ui/
│ │ ├── components/
│ │ └── nuxt.config.ts
│ └── auth/
│ ├── composables/
│ └── nuxt.config.ts
└── nuxt.config.ts
Module Ecosystem
# Key modules
npx nuxi module add @nuxt/image
npx nuxi module add @nuxt/ui
npx nuxi module add @nuxtjs/i18n
npx nuxi module add @pinia/nuxt
Migration Guide
# Automatic migration
npx nuxi upgrade --force
# Codemod
npx codemod nuxt/4/new-directory-structure
Major Breaking Changes
| Change | Action |
|---|---|
| Directory structure | Move to app/ directory |
| Vue 3.4+ required | Upgrade Vue |
| Some composable API changes | Refer to documentation |
Summary
Nuxt 4 provides a more comfortable development experience with significant performance improvements and a new directory structure. It leverages the latest Vue 3 ecosystem features to build modern web applications.
← Back to list