Skip to content

Commit 1d76df6

Browse files
authored
fix: support nuxt 4 tsconfig structure (#3728)
1 parent cd74762 commit 1d76df6

27 files changed

Lines changed: 1368 additions & 485 deletions

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@nuxt/image": "^1.10.0",
2121
"@nuxt/scripts": "^0.11.8",
2222
"@nuxt/ui-pro": "^3.1.3",
23-
"nuxt": "^3.17.5",
23+
"nuxt": "^4.0.0",
2424
"nuxt-llms": "0.1.3",
2525
"nuxt-og-image": "^5.1.6",
2626
"shiki-transformer-color-highlight": "^1.0.0"

knip.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"entry": ["{components,layouts,pages,plugins,server}/**", "{app,error}.vue", "*.ts"]
3131
},
3232
"playground": {
33-
"entry": ["{components,layouts,pages,plugins,server}/**", "{app,error}.vue", "*.ts"],
33+
"entry": ["{app,server}/**", "{app,error}.vue", "*.ts"],
3434
"ignore": ["i18n/**"],
3535
"ignoreDependencies": ["@nuxtjs/i18n"]
3636
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@intlify/unplugin-vue-i18n": "^6.0.8",
9090
"@intlify/utils": "^0.13.0",
9191
"@miyaneee/rollup-plugin-json5": "^1.2.0",
92-
"@nuxt/kit": "^3.17.6",
92+
"@nuxt/kit": "^4.0.0",
9393
"@rollup/plugin-yaml": "^4.1.2",
9494
"@vue/compiler-sfc": "^3.5.17",
9595
"cookie-es": "^2.0.0",
@@ -116,7 +116,7 @@
116116
"@babel/types": "^7.27.3",
117117
"@eslint/js": "9.28.0",
118118
"@nuxt/module-builder": "^1.0.1",
119-
"@nuxt/schema": "^3.17.6",
119+
"@nuxt/schema": "^4.0.0",
120120
"@types/debug": "^4.1.12",
121121
"@types/estree": "^1.0.7",
122122
"@types/jsdom": "^21.1.7",
@@ -126,7 +126,7 @@
126126
"eslint": "^9.28.0",
127127
"eslint-config-prettier": "^10.1.5",
128128
"eslint-plugin-regexp": "^2.7.0",
129-
"get-port-please": "^3.1.2",
129+
"get-port-please": "^3.2.0",
130130
"gh-changelogen": "^0.2.8",
131131
"globals": "^16.2.0",
132132
"jiti": "^2.4.2",
@@ -135,7 +135,7 @@
135135
"lint-staged": "^15.5.0",
136136
"nitropack": "^2.11.13",
137137
"npm-run-all2": "^6.2.6",
138-
"nuxt": "^3.17.6",
138+
"nuxt": "^4.0.0",
139139
"ofetch": "^1.4.1",
140140
"playwright-core": "^1.52.0",
141141
"prettier": "^3.5.3",

playground/tsconfig.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2-
// https://nuxt.com/docs/guide/concepts/typescript
3-
"extends": "./.nuxt/tsconfig.json"
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./.nuxt/tsconfig.app.json"
6+
},
7+
{
8+
"path": "./.nuxt/tsconfig.server.json"
9+
},
10+
{
11+
"path": "./.nuxt/tsconfig.shared.json"
12+
},
13+
{
14+
"path": "./.nuxt/tsconfig.node.json"
15+
}
16+
]
417
}

pnpm-lock.yaml

Lines changed: 1282 additions & 440 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/alias.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
UFO_PKG,
1111
NUXT_I18N_MODULE_ID
1212
} from './constants'
13+
import { defu } from 'defu'
14+
import { resolveI18nDir } from './layers'
15+
import { getLayerI18n } from './utils'
16+
import { relative, resolve } from 'pathe'
1317

1418
import type { Nuxt } from '@nuxt/schema'
1519
import type { I18nNuxtContext } from './context'
@@ -25,6 +29,29 @@ export function setupAlias({ userOptions: options }: I18nNuxtContext, nuxt: Nuxt
2529
[UFO_PKG]: UFO_PKG
2630
} as const
2731

32+
const layerI18nDirs = nuxt.options._layers
33+
.map(l => {
34+
const i18n = getLayerI18n(l)
35+
if (i18n == null) return undefined
36+
return relative(nuxt.options.buildDir, resolve(resolveI18nDir(l, i18n), '**/*'))
37+
})
38+
.filter((x): x is string => !!x)
39+
40+
nuxt.options.typescript = defu(nuxt.options.typescript, {
41+
hoist: Object.keys(modules),
42+
tsConfig: {
43+
include: layerI18nDirs
44+
}
45+
})
46+
47+
const optimize = Object.keys(modules)
48+
optimize.push(UTILS_PKG, 'cookie-es')
49+
nuxt.options.vite = defu(nuxt.options.vite, {
50+
optimizeDeps: {
51+
include: optimize
52+
}
53+
})
54+
2855
const moduleDirs = ([] as string[])
2956
.concat(
3057
nuxt.options.modulesDir,

src/gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function generateLoaderOptions(
4747
load: genDynamicImport(asI18nVirtual(meta.hash), { comment: `webpackChunkName: ${key}` })
4848
})
4949
}
50-
localeLoaders[locale.code].push(importMapper.get(meta.path)!)
50+
localeLoaders[locale.code]!.push(importMapper.get(meta.path)!)
5151
}
5252
}
5353

@@ -56,7 +56,7 @@ export function generateLoaderOptions(
5656
*/
5757
const vueI18nConfigs = []
5858
for (let i = ctx.vueI18nConfigPaths.length - 1; i >= 0; i--) {
59-
const config = ctx.vueI18nConfigPaths[i]
59+
const config = ctx.vueI18nConfigPaths[i]!
6060
const key = genString(`config_${genSafeVariableName(basename(config.path))}_${config.hash}`)
6161
vueI18nConfigs.push({
6262
importer: genDynamicImport(asI18nVirtual(config.hash), { comment: `webpackChunkName: ${key}` }),

0 commit comments

Comments
 (0)