Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nuxtPublic

Commit7db30a6

Browse files
authored
fix(vite): unsetoptimizeDeps.include for server environment (#33550)
1 parent904d4f6 commit7db30a6

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

‎packages/nuxt/src/core/plugins/resolved-externals.ts‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
1212
return{
1313
name:'nuxt:resolve-externals',
1414
enforce:'pre',
15-
asyncapplyToEnvironment(environment){
16-
if(nuxt.options.dev||environment.name!=='ssr'){
17-
returnfalse
18-
}
19-
15+
asyncconfig(){
2016
const{runtimeDependencies:runtimeNitroDependencies=[]}=awaittryImportModule<typeofimport('nitropack/runtime/meta')>('nitropack/runtime/meta',{
2117
url:newURL(import.meta.url),
2218
})||{}
@@ -31,26 +27,38 @@ export function ResolveExternalsPlugin (nuxt: Nuxt): Plugin {
3127
...runtimeNitroDependencies,
3228
])
3329

34-
returntrue
30+
return{
31+
optimizeDeps:{
32+
exclude:Array.from(external),
33+
},
34+
}
3535
},
36-
asyncresolveId(id,importer){
37-
if(!external.has(id)){
38-
return
36+
applyToEnvironment(environment){
37+
if(nuxt.options.dev||environment.name!=='ssr'){
38+
returnfalse
3939
}
40+
return{
41+
name:'nuxt:resolve-externals:external',
42+
asyncresolveId(id,importer){
43+
if(!external.has(id)){
44+
return
45+
}
4046

41-
constres=awaitthis.resolve?.(id,importer,{skipSelf:true})
42-
if(res!==undefined&&res!==null){
43-
if(res.id===id){
44-
res.id=resolveModulePath(res.id,{
45-
try:true,
46-
from:importer,
47-
extensions:nuxt.options.extensions,
48-
})||res.id
49-
}
50-
return{
51-
...res,
52-
external:'absolute',
53-
}
47+
constres=awaitthis.resolve?.(id,importer,{skipSelf:true})
48+
if(res!==undefined&&res!==null){
49+
if(res.id===id){
50+
res.id=resolveModulePath(res.id,{
51+
try:true,
52+
from:importer,
53+
extensions:nuxt.options.extensions,
54+
})||res.id
55+
}
56+
return{
57+
...res,
58+
external:'absolute',
59+
}
60+
}
61+
},
5462
}
5563
},
5664
}

‎packages/vite/src/plugins/environments.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@ export function EnvironmentsPlugin (nuxt: Nuxt): Plugin {
2020
'#app-manifest':resolveModulePath('mocked-exports/empty',{from:import.meta.url}),
2121
}
2222

23+
letviteConfig:vite.InlineConfig
24+
2325
return{
2426
name:'nuxt:environments',
25-
config(){
27+
config(config){
28+
viteConfig=config
2629
if(!nuxt.options.dev){
2730
return{
2831
base:'./',
2932
}
3033
}
3134
},
3235
configEnvironment(name,config){
36+
if(!nuxt.options.experimental.viteEnvironmentApi&&viteConfig.ssr){
37+
config.optimizeDeps||={}
38+
config.optimizeDeps.include=undefined
39+
}
3340
if(name==='client'){
3441
constoutputConfig=config.build?.rollupOptions?.outputasvite.Rollup.OutputOptions
3542
return{
@@ -54,8 +61,11 @@ export function EnvironmentsPlugin (nuxt: Nuxt): Plugin {
5461
}
5562

5663
if(name==='ssr'){
64+
// Disable manual chunks for SSR environment to avoid splitting issues
5765
if(config.build?.rollupOptions?.output&&!Array.isArray(config.build.rollupOptions.output)){
5866
config.build.rollupOptions.output.manualChunks=undefined
67+
68+
// Also disable advancedChunks when using Rolldown
5969
if((viteasany).rolldownVersion){
6070
(config.build.rollupOptions.outputasany).advancedChunks=undefined
6171
}

‎packages/vite/src/shared/client.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ export const clientEnvironment = (nuxt: Nuxt, entry: string) => {
2626
'@vue/reactivity',
2727
'@vue/shared',
2828
'@vue/devtools-api',
29+
'@vue/test-utils',
2930
'vue-router',
3031
'vue-demi',
3132

3233
// Nuxt
3334
'nuxt',
3435
'nuxt/app',
36+
'@nuxt/test-utils',
3537

3638
// Nuxt Deps
3739
'@unhead/vue',
3840
'consola',
3941
'defu',
4042
'devalue',
43+
'get-port-please',
4144
'h3',
4245
'hookable',
4346
'klona',
@@ -47,8 +50,17 @@ export const clientEnvironment = (nuxt: Nuxt, entry: string) => {
4750
'unctx',
4851
'unenv',
4952

50-
//these will never be imported on the client
53+
//this will never be imported on the client
5154
'#app-manifest',
55+
// these should all be valid ESM
56+
'#imports',
57+
'#app',
58+
'#build',
59+
'#build/*',
60+
'#components',
61+
'#head',
62+
'virtual:nuxt:',
63+
'virtual:nuxt:*',
5264
],
5365
},
5466
define:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp