@@ -385,6 +385,7 @@ export async function runOptimizeDeps(
385
385
resolvedConfig : ResolvedConfig ,
386
386
depsInfo : Record < string , OptimizedDepInfo >
387
387
) : Promise < DepOptimizationResult > {
388
+ const isBuild = resolvedConfig . command === 'build'
388
389
const config : ResolvedConfig = {
389
390
...resolvedConfig ,
390
391
command : 'build'
@@ -471,30 +472,24 @@ export async function runOptimizeDeps(
471
472
flatIdToExports [ flatId ] = exportsData
472
473
}
473
474
474
- const define : Record < string , string > = {
475
- 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV || config . mode )
476
- }
477
- for ( const key in config . define ) {
478
- const value = config . define [ key ]
479
- define [ key ] = typeof value === 'string' ? value : JSON . stringify ( value )
480
- }
481
-
482
475
const start = performance . now ( )
483
476
484
477
const result = await build ( {
485
478
absWorkingDir : process . cwd ( ) ,
486
479
entryPoints : Object . keys ( flatIdDeps ) ,
487
480
bundle : true ,
481
+ // Ensure resolution is handled by esbuildDepPlugin and
482
+ // avoid replacing `process.env.NODE_ENV` for 'browser'
483
+ platform : 'neutral' ,
488
484
format : 'esm' ,
489
485
target : config . build . target || undefined ,
490
486
external : config . optimizeDeps ?. exclude ,
491
487
logLevel : 'error' ,
492
488
splitting : true ,
493
489
sourcemap : true ,
494
490
outdir : processingCacheDir ,
495
- ignoreAnnotations : resolvedConfig . command !== 'build' ,
491
+ ignoreAnnotations : ! isBuild ,
496
492
metafile : true ,
497
- define,
498
493
plugins : [
499
494
...plugins ,
500
495
esbuildDepPlugin ( flatIdDeps , flatIdToExports , config )
@@ -887,7 +882,6 @@ export function getDepHash(config: ResolvedConfig): string {
887
882
{
888
883
mode : process . env . NODE_ENV || config . mode ,
889
884
root : config . root ,
890
- define : config . define ,
891
885
resolve : config . resolve ,
892
886
buildTarget : config . build . target ,
893
887
assetsInclude : config . assetsInclude ,
0 commit comments