@@ -11,7 +11,6 @@ import {
11
11
DEP_VERSION_RE ,
12
12
ENV_ENTRY ,
13
13
FS_PREFIX ,
14
- OPTIMIZABLE_ENTRY_RE ,
15
14
SPECIAL_QUERY_RE ,
16
15
} from '../constants'
17
16
import {
@@ -36,7 +35,7 @@ import {
36
35
import type { ResolvedEnvironmentOptions } from '../config'
37
36
import { optimizedDepInfoFromFile , optimizedDepInfoFromId } from '../optimizer'
38
37
import type { DepsOptimizer } from '../optimizer'
39
- import type { DepOptimizationOptions , SSROptions } from '..'
38
+ import type { SSROptions } from '..'
40
39
import type { PackageCache , PackageData } from '../packages'
41
40
import { shouldExternalize } from '../external'
42
41
import {
@@ -129,8 +128,6 @@ interface ResolvePluginOptions {
129
128
isFromTsImporter ?: boolean
130
129
// True when resolving during the scan phase to discover dependencies
131
130
scan ?: boolean
132
- // Appends ?__vite_skip_optimization to the resolved id if shouldn't be optimized
133
- ssrOptimizeCheck ?: boolean
134
131
135
132
/**
136
133
* Optimize deps during dev, defaults to false // TODO: Review default
@@ -248,8 +245,6 @@ export function resolvePlugin(
248
245
scan : resolveOpts ?. scan ?? resolveOptions . scan ,
249
246
}
250
247
251
- const depsOptimizerOptions = this . environment . config . optimizeDeps
252
-
253
248
const resolvedImports = resolveSubpathImports ( id , importer , options )
254
249
if ( resolvedImports ) {
255
250
id = resolvedImports
@@ -337,14 +332,7 @@ export function resolvePlugin(
337
332
if (
338
333
options . webCompatible &&
339
334
options . mainFields . includes ( 'browser' ) &&
340
- ( res = tryResolveBrowserMapping (
341
- fsPath ,
342
- importer ,
343
- options ,
344
- true ,
345
- undefined ,
346
- depsOptimizerOptions ,
347
- ) )
335
+ ( res = tryResolveBrowserMapping ( fsPath , importer , options , true ) )
348
336
) {
349
337
return res
350
338
}
@@ -436,7 +424,6 @@ export function resolvePlugin(
436
424
options ,
437
425
false ,
438
426
external ,
439
- depsOptimizerOptions ,
440
427
) )
441
428
) {
442
429
return res
@@ -450,7 +437,6 @@ export function resolvePlugin(
450
437
depsOptimizer ,
451
438
external ,
452
439
undefined ,
453
- depsOptimizerOptions ,
454
440
) )
455
441
) {
456
442
return res
@@ -742,7 +728,6 @@ export function tryNodeResolve(
742
728
depsOptimizer ?: DepsOptimizer ,
743
729
externalize ?: boolean ,
744
730
allowLinkedExternal : boolean = true ,
745
- depsOptimizerOptions ?: DepOptimizationOptions ,
746
731
) : PartialResolvedId | undefined {
747
732
const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options
748
733
@@ -846,10 +831,7 @@ export function tryNodeResolve(
846
831
return { ...resolved , id : resolvedId , external : true }
847
832
}
848
833
849
- if (
850
- ! options . idOnly &&
851
- ( ( ! options . scan && isBuild && ! depsOptimizer ) || externalize )
852
- ) {
834
+ if ( ! options . idOnly && ( ( ! options . scan && isBuild ) || externalize ) ) {
853
835
// Resolve package side effects for build so that rollup can better
854
836
// perform tree-shaking
855
837
return processResult ( {
@@ -859,70 +841,43 @@ export function tryNodeResolve(
859
841
}
860
842
861
843
if (
862
- ! options . ssrOptimizeCheck &&
863
- ( ! isInNodeModules ( resolved ) || // linked
864
- ! depsOptimizer || // resolving before listening to the server
865
- options . scan ) // initial esbuild scan phase
844
+ ! isInNodeModules ( resolved ) || // linked
845
+ ! depsOptimizer || // resolving before listening to the server
846
+ options . scan // initial esbuild scan phase
866
847
) {
867
848
return { id : resolved }
868
849
}
869
850
870
851
// if we reach here, it's a valid dep import that hasn't been optimized.
871
- const isJsType = depsOptimizer
872
- ? isOptimizable ( resolved , depsOptimizer . options )
873
- : OPTIMIZABLE_ENTRY_RE . test ( resolved )
874
-
875
- let exclude = depsOptimizer ?. options . exclude
876
- if ( options . ssrOptimizeCheck ) {
877
- // we don't have the depsOptimizer
878
- exclude = depsOptimizerOptions ?. exclude
879
- }
852
+ const isJsType = isOptimizable ( resolved , depsOptimizer . options )
853
+ const exclude = depsOptimizer . options . exclude
880
854
881
855
const skipOptimization =
882
- ( ! options . ssrOptimizeCheck && depsOptimizer ? .options . noDiscovery ) ||
856
+ depsOptimizer . options . noDiscovery ||
883
857
! isJsType ||
884
858
( importer && isInNodeModules ( importer ) ) ||
885
859
exclude ?. includes ( pkgId ) ||
886
860
exclude ?. includes ( id ) ||
887
861
SPECIAL_QUERY_RE . test ( resolved )
888
862
889
- if ( options . ssrOptimizeCheck ) {
890
- return {
891
- id : skipOptimization
892
- ? injectQuery ( resolved , `__vite_skip_optimization` )
893
- : resolved ,
894
- }
895
- }
896
-
897
863
if ( skipOptimization ) {
898
864
// excluded from optimization
899
865
// Inject a version query to npm deps so that the browser
900
866
// can cache it without re-validation, but only do so for known js types.
901
867
// otherwise we may introduce duplicated modules for externalized files
902
868
// from pre-bundled deps.
903
- if ( ! isBuild ) {
904
- const versionHash = depsOptimizer ! . metadata . browserHash
905
- if ( versionHash && isJsType ) {
906
- resolved = injectQuery ( resolved , `v=${ versionHash } ` )
907
- }
869
+ const versionHash = depsOptimizer . metadata . browserHash
870
+ if ( versionHash && isJsType ) {
871
+ resolved = injectQuery ( resolved , `v=${ versionHash } ` )
908
872
}
909
873
} else {
910
874
// this is a missing import, queue optimize-deps re-run and
911
875
// get a resolved its optimized info
912
- const optimizedInfo = depsOptimizer ! . registerMissingImport ( id , resolved )
913
- resolved = depsOptimizer ! . getOptimizedDepId ( optimizedInfo )
876
+ const optimizedInfo = depsOptimizer . registerMissingImport ( id , resolved )
877
+ resolved = depsOptimizer . getOptimizedDepId ( optimizedInfo )
914
878
}
915
879
916
- if ( ! options . idOnly && ! options . scan && isBuild ) {
917
- // Resolve package side effects for build so that rollup can better
918
- // perform tree-shaking
919
- return {
920
- id : resolved ,
921
- moduleSideEffects : pkg . hasSideEffects ( resolved ) ,
922
- }
923
- } else {
924
- return { id : resolved ! }
925
- }
880
+ return { id : resolved }
926
881
}
927
882
928
883
export async function tryOptimizedResolve (
@@ -1186,7 +1141,6 @@ function tryResolveBrowserMapping(
1186
1141
options : InternalResolveOptions ,
1187
1142
isFilePath : boolean ,
1188
1143
externalize ?: boolean ,
1189
- depsOptimizerOptions ?: DepOptimizationOptions ,
1190
1144
) {
1191
1145
let res : string | undefined
1192
1146
const pkg =
@@ -1205,7 +1159,6 @@ function tryResolveBrowserMapping(
1205
1159
undefined ,
1206
1160
undefined ,
1207
1161
undefined ,
1208
- depsOptimizerOptions ,
1209
1162
) ?. id
1210
1163
: tryFsResolve ( path . join ( pkg . dir , browserMappedPath ) , options ) )
1211
1164
) {
0 commit comments