@@ -48,6 +48,7 @@ import {
48
48
import { optionsProxy , toInternalSourceLocation } from '../utils' ;
49
49
import { fromProjectPath , toProjectPath , joinProjectPath } from '../projectPath' ;
50
50
import { requestTypes } from '../RequestTracker' ;
51
+ import { BROWSER_ENVS } from '../public/Environment' ;
51
52
52
53
type RunOpts < TResult > = { |
53
54
input : Entry ,
@@ -78,7 +79,7 @@ const COMMON_TARGETS = {
78
79
} ;
79
80
80
81
const DEFAULT_ENGINES = {
81
- node : 'current' ,
82
+ node : process . versions . node ,
82
83
browsers : [
83
84
'last 1 Chrome version' ,
84
85
'last 1 Safari version' ,
@@ -345,26 +346,41 @@ export class TargetResolver {
345
346
) ;
346
347
}
347
348
} else {
349
+ targets = Array . from ( packageTargets . values ( ) )
350
+ . filter ( Boolean )
351
+ . filter ( descriptor => {
352
+ return (
353
+ descriptor &&
354
+ ! skipTarget ( descriptor . name , exclusiveTarget , descriptor . source )
355
+ ) ;
356
+ } ) ;
357
+
348
358
// Explicit targets were not provided. Either use a modern target for server
349
359
// mode, or simply use the package.json targets.
350
360
if ( this . options . serveOptions ) {
351
361
// In serve mode, we only support a single browser target. Since the user
352
362
// hasn't specified a target, use one targeting modern browsers for development
363
+ let distDir = toProjectPath (
364
+ this . options . projectRoot ,
365
+ this . options . serveOptions . distDir ,
366
+ ) ;
367
+ let context = targets [ 0 ] ?. env . context ?? 'browser' ;
368
+ let engines = BROWSER_ENVS . has ( context )
369
+ ? { browsers : DEFAULT_ENGINES . browsers }
370
+ : { node : DEFAULT_ENGINES . node } ;
353
371
targets = [
354
372
{
355
373
name : 'default' ,
356
- distDir : toProjectPath (
357
- this . options . projectRoot ,
358
- this . options . serveOptions . distDir ,
359
- ) ,
374
+ distDir,
360
375
publicUrl : this . options . defaultTargetOptions . publicUrl ?? '/' ,
361
376
env : createEnvironment ( {
362
- context : 'browser' ,
363
- engines : {
364
- browsers : DEFAULT_ENGINES . browsers ,
365
- } ,
377
+ context,
378
+ engines,
379
+ includeNodeModules : targets [ 0 ] ?. env . includeNodeModules ,
366
380
shouldOptimize : this . options . defaultTargetOptions . shouldOptimize ,
367
- outputFormat : this . options . defaultTargetOptions . outputFormat ,
381
+ outputFormat :
382
+ targets [ 0 ] ?. env . outputFormat ??
383
+ this . options . defaultTargetOptions . outputFormat ,
368
384
shouldScopeHoist :
369
385
this . options . defaultTargetOptions . shouldScopeHoist ,
370
386
sourceMap : this . options . defaultTargetOptions . sourceMaps
@@ -373,15 +389,6 @@ export class TargetResolver {
373
389
} ) ,
374
390
} ,
375
391
] ;
376
- } else {
377
- targets = Array . from ( packageTargets . values ( ) )
378
- . filter ( Boolean )
379
- . filter ( descriptor => {
380
- return (
381
- descriptor &&
382
- ! skipTarget ( descriptor . name , exclusiveTarget , descriptor . source )
383
- ) ;
384
- } ) ;
385
392
}
386
393
}
387
394
0 commit comments