Skip to content

Commit e55ab8f

Browse files
danielroeatinuxDamianGlowala
authored
feat: add blog post for v4.1/v3.19 release (#2020)
Co-authored-by: Sébastien Chopin <[email protected]> Co-authored-by: Damian Głowala <[email protected]>
1 parent 6e860ea commit e55ab8f

File tree

3 files changed

+293
-2
lines changed

3 files changed

+293
-2
lines changed

content/blog/38.v4-1.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
---
2+
title: Nuxt 4.1
3+
description: Nuxt 4.1 is out - bringing enhanced build stability, better development experience, and powerful new features for module authors!
4+
navigation: false
5+
image: /assets/blog/v4.1.png
6+
authors:
7+
- name: Daniel Roe
8+
avatar:
9+
src: https://github.com/danielroe.png
10+
to: https://bsky.app/profile/danielroe.dev
11+
date: 2025-09-02T10:00:00.000Z
12+
category: Release
13+
---
14+
15+
## 🔥 Build and Performance Improvements
16+
17+
### 🍫 Enhanced Chunk Stability
18+
19+
Build stability has been significantly improved with import maps ([#33075](https://github.com/nuxt/nuxt/pull/33075)). This prevents cascading hash changes that could invalidate large portions of your build when small changes are made:
20+
21+
```html
22+
<!-- Automatically injected import map -->
23+
<script type="importmap">{"imports":{"#entry":"/_nuxt/DC5HVSK5.js"}}</script>
24+
```
25+
26+
By default, JS chunks emitted in a Vite build are hashed, which means they can be cached immutably. However, this can cause a significant issue: a change to a single component can cause _every_ hash to be invalidated, massively increasing the chance of 404s.
27+
28+
In short:
29+
30+
1. a component is changed slightly - the hash of its JS chunk changes
31+
2. the page which uses the component has to be updated to reference the new file name
32+
3. the _entry_ now has its hash changed because it dynamically imports the page
33+
4. _**every other file**_ which imports the entry has its hash changed because the entry file name is changed
34+
35+
Obviously this wasn't optimal. With this new feature, the hash of (otherwise) unchanged files which import the entry won't be affected.
36+
37+
This feature is automatically enabled and helps maintain better cache efficiency in production. It does require [native import map support](https://caniuse.com/import-maps), but Nuxt will automatically disable it if you have configured `vite.build.target` to include a browser that doesn't support import maps.
38+
39+
And of course you can disable it if needed:
40+
41+
```ts [nuxt.config.ts]
42+
export default defineNuxtConfig({
43+
experimental: {
44+
entryImportMap: false
45+
}
46+
})
47+
```
48+
49+
### 🦀 Experimental Rolldown Support
50+
51+
Nuxt now includes experimental support for `rolldown-vite` ([#31812](https://github.com/nuxt/nuxt/pull/31812)), bringing Rust-powered bundling for potentially faster builds.
52+
53+
To try Rolldown in your Nuxt project, you need to override Vite with the rolldown-powered version since Vite is a dependency of Nuxt. Add the following to your `package.json`:
54+
55+
::code-group{sync="pm"}
56+
```json [npm]
57+
{
58+
"overrides": {
59+
"vite": "npm:rolldown-vite@latest"
60+
}
61+
}
62+
```
63+
64+
```json [pnpm]
65+
{
66+
"pnpm": {
67+
"overrides": {
68+
"vite": "npm:rolldown-vite@latest"
69+
}
70+
}
71+
}
72+
```
73+
74+
```json [yarn]
75+
{
76+
"resolutions": {
77+
"vite": "npm:rolldown-vite@latest"
78+
}
79+
}
80+
```
81+
82+
```json [bun]
83+
{
84+
"overrides": {
85+
"vite": "npm:rolldown-vite@latest"
86+
}
87+
}
88+
```
89+
::
90+
91+
After adding the override, reinstall your dependencies. Nuxt will automatically detect when Rolldown is available and adjust its build configuration accordingly.
92+
93+
For more details on Rolldown integration, see the [Vite Rolldown guide](https://vite.dev/guide/rolldown).
94+
95+
::note
96+
This is experimental and may have some limitations, but offers a glimpse into the future of high-performance bundling in Nuxt.
97+
::
98+
99+
## 🧪 Improved Lazy Hydration
100+
101+
Lazy hydration macros now work without auto-imports ([#33037](https://github.com/nuxt/nuxt/pull/33037)), making them more reliable when component auto-discovery is disabled:
102+
103+
```vue
104+
<script setup>
105+
// Works even with components: false
106+
const LazyComponent = defineLazyHydrationComponent(
107+
'visible',
108+
() => import('./MyComponent.vue')
109+
)
110+
</script>
111+
```
112+
113+
This ensures that components that are not "discovered" through Nuxt (e.g., because `components` is set to `false` in the config) can still be used in lazy hydration macros.
114+
115+
## 📄 Enhanced Page Rules
116+
117+
If you have enabled experimental extraction of route rules, these are now exposed on a dedicated `rules` property on `NuxtPage` objects ([#32897](https://github.com/nuxt/nuxt/pull/32897)), making them more accessible to modules and improving the overall architecture:
118+
119+
```ts
120+
// In your module
121+
nuxt.hook('pages:extend', pages => {
122+
pages.push({
123+
path: '/api-docs',
124+
rules: {
125+
prerender: true,
126+
cors: true,
127+
headers: { 'Cache-Control': 's-maxage=31536000' }
128+
}
129+
})
130+
})
131+
```
132+
133+
The `defineRouteRules` function continues to work exactly as before, but now provides better integration possibilities for modules.
134+
135+
## 🚀 Module Development Enhancements
136+
137+
### 🪾 Module Dependencies and Integration
138+
139+
Modules can now specify dependencies and modify options for other modules ([#33063](https://github.com/nuxt/nuxt/pull/33063)). This enables better module integration and ensures proper setup order:
140+
141+
```ts
142+
export default defineNuxtModule({
143+
meta: {
144+
name: 'my-module',
145+
},
146+
moduleDependencies: {
147+
'some-module': {
148+
// You can specify a version constraint for the module
149+
version: '>=2',
150+
// By default moduleDependencies will be added to the list of modules
151+
// to be installed by Nuxt unless `optional` is set.
152+
optional: true,
153+
// Any configuration that should override `nuxt.options`.
154+
overrides: {},
155+
// Any configuration that should be set. It will override module defaults but
156+
// will not override any configuration set in `nuxt.options`.
157+
defaults: {}
158+
}
159+
},
160+
setup (options, nuxt) {
161+
// Your module setup logic
162+
}
163+
})
164+
```
165+
166+
This replaces the deprecated `installModule` function and provides a more robust way to handle module dependencies with version constraints and configuration merging.
167+
168+
### 🪝 Module Lifecycle Hooks
169+
170+
Module authors now have access to two new lifecycle hooks: `onInstall` and `onUpgrade` ([#32397](https://github.com/nuxt/nuxt/pull/32397)). These hooks allow modules to perform additional setup steps when first installed or when upgraded to a new version:
171+
172+
```ts
173+
export default defineNuxtModule({
174+
meta: {
175+
name: 'my-module',
176+
version: '1.0.0',
177+
},
178+
179+
onInstall(nuxt) {
180+
// This will be run when the module is first installed
181+
console.log('Setting up my-module for the first time!')
182+
},
183+
184+
onUpgrade(inlineOptions, nuxt, previousVersion) {
185+
// This will be run when the module is upgraded
186+
console.log(`Upgrading my-module from v${previousVersion}`)
187+
}
188+
})
189+
```
190+
191+
The hooks are only triggered when both `name` and `version` are provided in the module metadata. Nuxt uses the `.nuxtrc` file internally to track module versions and trigger the appropriate hooks. (If you haven't come across it before, the `.nuxtrc` file should be committed to version control.)
192+
193+
::tip
194+
This means module authors can begin implementing their own 'setup wizards' to provide a better experience when some setup is required after installing a module.
195+
::
196+
197+
### 🙈 Enhanced File Resolution
198+
199+
The new `ignore` option for `resolveFiles` ([#32858](https://github.com/nuxt/nuxt/pull/32858)) allows module authors to exclude specific files based on glob patterns:
200+
201+
```ts
202+
// Resolve all .vue files except test files
203+
const files = await resolveFiles(srcDir, '**/*.vue', {
204+
ignore: ['**/*.test.vue', '**/__tests__/**']
205+
})
206+
```
207+
208+
### 📂 Layer Directories Utility
209+
210+
A new `getLayerDirectories` utility ([#33098](https://github.com/nuxt/nuxt/pull/33098)) provides a clean interface for accessing layer directories without directly accessing private APIs:
211+
212+
```ts
213+
import { getLayerDirectories } from '@nuxt/kit'
214+
215+
const layerDirs = await getLayerDirectories(nuxt)
216+
// Access key directories:
217+
// layerDirs.app - /app/ by default
218+
// layerDirs.appPages - /app/pages by default
219+
// layerDirs.server - /server by default
220+
// layerDirs.public - /public by default
221+
```
222+
223+
## ✨ Developer Experience Improvements
224+
225+
### 🎱 Simplified Kit Utilities
226+
227+
Several kit utilities have been improved for better developer experience:
228+
229+
- `addServerImports` now supports single imports ([#32289](https://github.com/nuxt/nuxt/pull/32289)):
230+
231+
```ts
232+
// Before: required array
233+
addServerImports([{ from: 'my-package', name: 'myUtility' }])
234+
235+
// Now: can pass directly
236+
addServerImports({ from: 'my-package', name: 'myUtility' })
237+
```
238+
239+
### 🔥 Performance Optimizations
240+
241+
This release includes several internal performance optimizations:
242+
243+
- Improved route rules cache management ([#32877](https://github.com/nuxt/nuxt/pull/32877))
244+
- Optimized app manifest watching ([#32880](https://github.com/nuxt/nuxt/pull/32880))
245+
- Better TypeScript processing for page metadata ([#32920](https://github.com/nuxt/nuxt/pull/32920))
246+
247+
## 🐛 Notable Fixes
248+
249+
- Improved `useFetch` hook typing ([#32891](https://github.com/nuxt/nuxt/pull/32891))
250+
- Better handling of TypeScript expressions in page metadata ([#32902](https://github.com/nuxt/nuxt/pull/32902), [#32914](https://github.com/nuxt/nuxt/pull/32914))
251+
- Enhanced route matching and synchronization ([#32899](https://github.com/nuxt/nuxt/pull/32899))
252+
- Reduced verbosity of Vue server warnings in development ([#33018](https://github.com/nuxt/nuxt/pull/33018))
253+
- Better handling of relative time calculations in `<NuxtTime>` ([#32893](https://github.com/nuxt/nuxt/pull/32893))
254+
255+
## ✅ Upgrading
256+
257+
As usual, our recommendation for upgrading is to run:
258+
259+
```sh
260+
npx nuxt upgrade --dedupe
261+
```
262+
263+
This will refresh your lockfile and pull in all the latest dependencies that Nuxt relies on, especially from the unjs ecosystem.
264+
265+
## 📦 Nuxt 3.19
266+
267+
All of these features are also available in **Nuxt 3.19**, which has been released alongside v4.1. As part of our commitment to the v3 branch, we continue to backport compatible v4 features to ensure v3 users can benefit from the latest improvements.
268+
269+
If you're still using Nuxt 3, you can upgrade to v3.19 to get access to all these features while staying on the stable v3 release line.
270+
271+
## Full release notes
272+
273+
::read-more
274+
---
275+
icon: i-simple-icons-github
276+
target: _blank
277+
to: https://github.com/nuxt/nuxt/releases/tag/v4.1.0
278+
---
279+
Read the full release notes of Nuxt `v4.1.0`.
280+
::
281+
282+
::read-more
283+
---
284+
icon: i-simple-icons-github
285+
target: _blank
286+
to: https://github.com/nuxt/nuxt/releases/tag/v3.19.0
287+
---
288+
Read the full release notes of Nuxt `v3.19.0`.
289+
::
290+
291+
Thank you to everyone who contributed! We're excited to see what you build with these new features. ❤️

content/index.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ hero:
22
title: 'The Progressive Web Framework'
33
description: Create high-quality web applications with Nuxt, the open source framework that makes full-stack development with Vue.js intuitive.
44
cta:
5-
label: Nuxt v3.18 is out
6-
to: /blog/v3-18
5+
label: Nuxt v4.1 is out
6+
to: /blog/v4-1
77
icon: i-lucide-arrow-right
88
tabs:
99
- title: Minimal

public/assets/blog/v4.1.png

495 KB
Loading

0 commit comments

Comments
 (0)