Skip to content

Commit 581ee18

Browse files
committed
Revert "feat: disable minify by default in development"
This reverts commit 2af81b7.
1 parent 81e38b8 commit 581ee18

File tree

3 files changed

+32
-44
lines changed

3 files changed

+32
-44
lines changed

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url'
33
import { stripVTControlCharacters } from 'node:util'
44
import fsp from 'node:fs/promises'
55
import colors from 'picocolors'
6-
import { afterEach, describe, expect, onTestFinished, test, vi } from 'vitest'
6+
import { afterEach, describe, expect, test, vi } from 'vitest'
77
import type {
88
LogLevel,
99
OutputChunk,
@@ -809,13 +809,6 @@ test('default sharedConfigBuild true on build api', async () => {
809809
test.for([true, false])(
810810
'minify per environment (builder.sharedPlugins: %s)',
811811
async (sharedPlugins) => {
812-
const _nodeEnv = process.env.NODE_ENV
813-
// Overriding the NODE_ENV set by vitest
814-
process.env.NODE_ENV = ''
815-
onTestFinished(() => {
816-
process.env.NODE_ENV = _nodeEnv
817-
})
818-
819812
const root = resolve(__dirname, 'fixtures/shared-plugins/minify')
820813
const builder = await createBuilder({
821814
root,

packages/vite/src/node/build.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ export function resolveBuildEnvironmentOptions(
396396
raw: BuildEnvironmentOptions,
397397
logger: Logger,
398398
consumer: 'client' | 'server' | undefined,
399-
isProduction: boolean,
400399
): ResolvedBuildEnvironmentOptions {
401400
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload
402401
const { polyfillModulePreload, ...rest } = raw
@@ -417,7 +416,7 @@ export function resolveBuildEnvironmentOptions(
417416
{
418417
...buildEnvironmentOptionsDefaults,
419418
cssCodeSplit: !raw.lib,
420-
minify: !isProduction || consumer === 'server' ? false : 'oxc',
419+
minify: consumer === 'server' ? false : 'oxc',
421420
rollupOptions: {
422421
platform: consumer === 'server' ? 'node' : 'browser',
423422
},

packages/vite/src/node/config.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,6 @@ function resolveEnvironmentOptions(
822822
preserveSymlinks: boolean,
823823
forceOptimizeDeps: boolean | undefined,
824824
logger: Logger,
825-
isProduction: boolean,
826825
environmentName: string,
827826
// Backward compatibility
828827
skipSsrTransform?: boolean,
@@ -888,7 +887,6 @@ function resolveEnvironmentOptions(
888887
options.build ?? {},
889888
logger,
890889
consumer,
891-
isProduction,
892890
),
893891
// will be set by `setOptimizeDepsPluginNames` later
894892
optimizeDepsPluginNames: undefined!,
@@ -1447,36 +1445,6 @@ export async function resolveConfig(
14471445
config.ssr?.target === 'webworker',
14481446
)
14491447

1450-
// load .env files
1451-
// Backward compatibility: set envDir to false when envFile is false
1452-
let envDir = config.envFile === false ? false : config.envDir
1453-
if (envDir !== false) {
1454-
envDir = config.envDir
1455-
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1456-
: resolvedRoot
1457-
}
1458-
1459-
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1460-
1461-
// Note it is possible for user to have a custom mode, e.g. `staging` where
1462-
// development-like behavior is expected. This is indicated by NODE_ENV=development
1463-
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1464-
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1465-
if (!isNodeEnvSet && userNodeEnv) {
1466-
if (userNodeEnv === 'development') {
1467-
process.env.NODE_ENV = 'development'
1468-
} else {
1469-
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1470-
logger.warn(
1471-
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1472-
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1473-
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1474-
)
1475-
}
1476-
}
1477-
1478-
const isProduction = process.env.NODE_ENV === 'production'
1479-
14801448
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
14811449
config.resolve ??= {}
14821450
config.resolve.conditions = config.environments.client.resolve?.conditions
@@ -1492,7 +1460,6 @@ export async function resolveConfig(
14921460
resolvedDefaultResolve.preserveSymlinks,
14931461
inlineConfig.forceOptimizeDeps,
14941462
logger,
1495-
isProduction,
14961463
environmentName,
14971464
config.experimental?.skipSsrTransform,
14981465
config.ssr?.target === 'webworker',
@@ -1518,7 +1485,6 @@ export async function resolveConfig(
15181485
config.build ?? {},
15191486
logger,
15201487
undefined,
1521-
isProduction,
15221488
)
15231489

15241490
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1539,6 +1505,36 @@ export async function resolveConfig(
15391505
resolvedDefaultResolve.preserveSymlinks,
15401506
)
15411507

1508+
// load .env files
1509+
// Backward compatibility: set envDir to false when envFile is false
1510+
let envDir = config.envFile === false ? false : config.envDir
1511+
if (envDir !== false) {
1512+
envDir = config.envDir
1513+
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1514+
: resolvedRoot
1515+
}
1516+
1517+
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1518+
1519+
// Note it is possible for user to have a custom mode, e.g. `staging` where
1520+
// development-like behavior is expected. This is indicated by NODE_ENV=development
1521+
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1522+
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1523+
if (!isNodeEnvSet && userNodeEnv) {
1524+
if (userNodeEnv === 'development') {
1525+
process.env.NODE_ENV = 'development'
1526+
} else {
1527+
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1528+
logger.warn(
1529+
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1530+
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1531+
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1532+
)
1533+
}
1534+
}
1535+
1536+
const isProduction = process.env.NODE_ENV === 'production'
1537+
15421538
// resolve public base url
15431539
const relativeBaseShortcut = config.base === '' || config.base === './'
15441540

0 commit comments

Comments
 (0)