Skip to content

Commit 1d2db3a

Browse files
committed
feat(nuxt): support Nuxt 4 and pre-bundle pinia-orm in dev
Upgrades the module to @nuxt/kit 4 / module-builder 1 with an explicit nuxt >=3.14 compatibility range. The module now adds pinia-orm to vite's optimizeDeps.include (opt-out via piniaOrm.optimizeDeps: false) to avoid dev server restarts when the first repository is used. Both playgrounds run on Nuxt 4 with pinia 4 and @pinia/nuxt 1.
1 parent b1fdd17 commit 1d2db3a

5 files changed

Lines changed: 4964 additions & 5032 deletions

File tree

docs/content/1.guide/5.nuxt/1.setup.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: ''
44

55
# Nuxt Setup
66

7+
Since version 2.0.0 the module supports **Nuxt 3.14+ and Nuxt 4**.
8+
79
## Installation
810

911
::alert{type=warning}
@@ -110,3 +112,17 @@ export default defineNuxtConfig({
110112
})
111113

112114
````
115+
116+
## Dependency Optimization
117+
118+
The module automatically adds `pinia-orm` to vite's `optimizeDeps.include`, so the dev server pre-bundles it and you don't get "new dependencies optimized — reloading" restarts when the first repository is used. If you want to handle dependency optimization yourself, disable it:
119+
120+
````ts
121+
// nuxt.config.ts
122+
export default defineNuxtConfig({
123+
modules: ['@pinia/nuxt', '@pinia-orm/nuxt'],
124+
piniaOrm: {
125+
optimizeDeps: false,
126+
},
127+
})
128+
````

packages/nuxt/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@
4242
"@pinia/nuxt": ">=0.10.0"
4343
},
4444
"dependencies": {
45-
"@nuxt/kit": "^3.15.4",
45+
"@nuxt/kit": "^4.5.0",
4646
"pinia-orm": "workspace:*"
4747
},
4848
"devDependencies": {
4949
"@nuxt/devtools": "^2.1.3",
5050
"@nuxt/eslint-config": "^1.1.0",
51-
"@nuxt/module-builder": "^0.8.4",
52-
"@nuxt/schema": "^3.15.4",
53-
"@pinia/nuxt": "^0.10.1",
51+
"@nuxt/module-builder": "^1.0.2",
52+
"@nuxt/schema": "^4.5.0",
53+
"@pinia/nuxt": "^1.0.1",
5454
"@types/prettier": "^3.0.0",
5555
"eslint": "^9.21.0",
56-
"nuxt": "^3.15.4",
57-
"pinia": "^3.0.1",
56+
"nuxt": "^4.5.0",
57+
"pinia": "^4.0.2",
5858
"prettier": "^3.3.2",
5959
"std-env": "^3.7.0",
6060
"typescript": "^5.8.2",

packages/nuxt/src/module.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ export interface PiniaOrmNuxtOptions extends InstallOptions {
2020
*
2121
*/
2222
autoImports?: Array<string | [string, string]>
23+
/**
24+
* Add pinia-orm packages to vite's `optimizeDeps.include` so the dev
25+
* server pre-bundles them and avoids "new dependency optimized" reloads.
26+
* @default true
27+
*/
28+
optimizeDeps?: boolean
2329
}
2430

2531
export default defineNuxtModule<PiniaOrmNuxtOptions>({
2632
meta: {
2733
name: 'pinia-orm',
2834
configKey: 'piniaOrm',
35+
compatibility: {
36+
nuxt: '>=3.14.0',
37+
},
2938
},
3039
defaults: {
3140
autoImports: [],
41+
optimizeDeps: true,
3242
...CONFIG_DEFAULTS,
3343
},
3444
setup (options, nuxt) {
@@ -37,6 +47,18 @@ export default defineNuxtModule<PiniaOrmNuxtOptions>({
3747
// Transpile runtime
3848
nuxt.options.build.transpile.push(resolver.resolve('./runtime'))
3949

50+
if (options.optimizeDeps) {
51+
// Pre-bundle pinia-orm so vite doesn't restart the dev server with
52+
// "new dependencies optimized" once the first repository is used.
53+
nuxt.options.vite.optimizeDeps ||= {}
54+
nuxt.options.vite.optimizeDeps.include ||= []
55+
for (const dep of ['pinia-orm', 'pinia-orm > @pinia-orm/normalizr']) {
56+
if (!nuxt.options.vite.optimizeDeps.include.includes(dep)) {
57+
nuxt.options.vite.optimizeDeps.include.push(dep)
58+
}
59+
}
60+
}
61+
4062
nuxt.hook('devtools:customTabs', (tabs) => {
4163
tabs.push({
4264
name: 'pinia-orm',

playgrounds/nuxt3/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"devDependencies": {
1111
"@pinia-orm/axios": "workspace:*",
1212
"@pinia-orm/nuxt": "workspace:*",
13-
"@pinia/nuxt": "^0.11.0",
14-
"nuxt": "^3.16.2",
15-
"pinia": "^3.0.2",
13+
"@pinia/nuxt": "^1.0.1",
14+
"nuxt": "^4.5.0",
15+
"pinia": "^4.0.2",
1616
"pinia-orm": "workspace:*"
1717
},
1818
"dependencies": {
1919
"axios": "^1.7.2",
20-
"nanoid": "^4.0.0",
21-
"uuid": "^8.3.2"
20+
"nanoid": "^5.1.0",
21+
"uuid": "^11.1.1"
2222
}
2323
}

0 commit comments

Comments
 (0)