@@ -812,7 +812,6 @@ function resolveEnvironmentOptions(
812
812
preserveSymlinks : boolean ,
813
813
forceOptimizeDeps : boolean | undefined ,
814
814
logger : Logger ,
815
- isProduction : boolean ,
816
815
environmentName : string ,
817
816
// Backward compatibility
818
817
isSsrTargetWebworkerSet ?: boolean ,
@@ -876,7 +875,6 @@ function resolveEnvironmentOptions(
876
875
options . build ?? { } ,
877
876
logger ,
878
877
consumer ,
879
- isProduction ,
880
878
) ,
881
879
plugins : undefined ! , // to be resolved later
882
880
// will be set by `setOptimizeDepsPluginNames` later
@@ -1446,36 +1444,6 @@ export async function resolveConfig(
1446
1444
config . ssr ?. target === 'webworker' ,
1447
1445
)
1448
1446
1449
- // load .env files
1450
- // Backward compatibility: set envDir to false when envFile is false
1451
- let envDir = config . envFile === false ? false : config . envDir
1452
- if ( envDir !== false ) {
1453
- envDir = config . envDir
1454
- ? normalizePath ( path . resolve ( resolvedRoot , config . envDir ) )
1455
- : resolvedRoot
1456
- }
1457
-
1458
- const userEnv = loadEnv ( mode , envDir , resolveEnvPrefix ( config ) )
1459
-
1460
- // Note it is possible for user to have a custom mode, e.g. `staging` where
1461
- // development-like behavior is expected. This is indicated by NODE_ENV=development
1462
- // loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1463
- const userNodeEnv = process . env . VITE_USER_NODE_ENV
1464
- if ( ! isNodeEnvSet && userNodeEnv ) {
1465
- if ( userNodeEnv === 'development' ) {
1466
- process . env . NODE_ENV = 'development'
1467
- } else {
1468
- // NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1469
- logger . warn (
1470
- `NODE_ENV=${ userNodeEnv } is not supported in the .env file. ` +
1471
- `Only NODE_ENV=development is supported to create a development build of your project. ` +
1472
- `If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.` ,
1473
- )
1474
- }
1475
- }
1476
-
1477
- const isProduction = process . env . NODE_ENV === 'production'
1478
-
1479
1447
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
1480
1448
config . resolve ??= { }
1481
1449
config . resolve . conditions = config . environments . client . resolve ?. conditions
@@ -1491,7 +1459,6 @@ export async function resolveConfig(
1491
1459
resolvedDefaultResolve . preserveSymlinks ,
1492
1460
inlineConfig . forceOptimizeDeps ,
1493
1461
logger ,
1494
- isProduction ,
1495
1462
environmentName ,
1496
1463
config . ssr ?. target === 'webworker' ,
1497
1464
config . server ?. preTransformRequests ,
@@ -1516,7 +1483,6 @@ export async function resolveConfig(
1516
1483
config . build ?? { } ,
1517
1484
logger ,
1518
1485
undefined ,
1519
- isProduction ,
1520
1486
)
1521
1487
1522
1488
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1537,6 +1503,36 @@ export async function resolveConfig(
1537
1503
resolvedDefaultResolve . preserveSymlinks ,
1538
1504
)
1539
1505
1506
+ // load .env files
1507
+ // Backward compatibility: set envDir to false when envFile is false
1508
+ let envDir = config . envFile === false ? false : config . envDir
1509
+ if ( envDir !== false ) {
1510
+ envDir = config . envDir
1511
+ ? normalizePath ( path . resolve ( resolvedRoot , config . envDir ) )
1512
+ : resolvedRoot
1513
+ }
1514
+
1515
+ const userEnv = loadEnv ( mode , envDir , resolveEnvPrefix ( config ) )
1516
+
1517
+ // Note it is possible for user to have a custom mode, e.g. `staging` where
1518
+ // development-like behavior is expected. This is indicated by NODE_ENV=development
1519
+ // loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1520
+ const userNodeEnv = process . env . VITE_USER_NODE_ENV
1521
+ if ( ! isNodeEnvSet && userNodeEnv ) {
1522
+ if ( userNodeEnv === 'development' ) {
1523
+ process . env . NODE_ENV = 'development'
1524
+ } else {
1525
+ // NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1526
+ logger . warn (
1527
+ `NODE_ENV=${ userNodeEnv } is not supported in the .env file. ` +
1528
+ `Only NODE_ENV=development is supported to create a development build of your project. ` +
1529
+ `If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.` ,
1530
+ )
1531
+ }
1532
+ }
1533
+
1534
+ const isProduction = process . env . NODE_ENV === 'production'
1535
+
1540
1536
// resolve public base url
1541
1537
const relativeBaseShortcut = config . base === '' || config . base === './'
1542
1538
0 commit comments