Skip to content

Commit 104da9e

Browse files
committed
Revert "feat: disable minify by default in development"
This reverts commit 2af81b7.
1 parent d4f1ebe commit 104da9e

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
@@ -397,7 +397,6 @@ export function resolveBuildEnvironmentOptions(
397397
raw: BuildEnvironmentOptions,
398398
logger: Logger,
399399
consumer: 'client' | 'server' | undefined,
400-
isProduction: boolean,
401400
): ResolvedBuildEnvironmentOptions {
402401
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload
403402
const { polyfillModulePreload, ...rest } = raw
@@ -418,7 +417,7 @@ export function resolveBuildEnvironmentOptions(
418417
{
419418
...buildEnvironmentOptionsDefaults,
420419
cssCodeSplit: !raw.lib,
421-
minify: !isProduction || consumer === 'server' ? false : 'oxc',
420+
minify: consumer === 'server' ? false : 'oxc',
422421
rollupOptions: {
423422
platform: consumer === 'server' ? 'node' : 'browser',
424423
},

packages/vite/src/node/config.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ function resolveEnvironmentOptions(
817817
preserveSymlinks: boolean,
818818
forceOptimizeDeps: boolean | undefined,
819819
logger: Logger,
820-
isProduction: boolean,
821820
environmentName: string,
822821
// Backward compatibility
823822
isSsrTargetWebworkerSet?: boolean,
@@ -881,7 +880,6 @@ function resolveEnvironmentOptions(
881880
options.build ?? {},
882881
logger,
883882
consumer,
884-
isProduction,
885883
),
886884
plugins: undefined!, // to be resolved later
887885
// will be set by `setOptimizeDepsPluginNames` later
@@ -1451,36 +1449,6 @@ export async function resolveConfig(
14511449
config.ssr?.target === 'webworker',
14521450
)
14531451

1454-
// load .env files
1455-
// Backward compatibility: set envDir to false when envFile is false
1456-
let envDir = config.envFile === false ? false : config.envDir
1457-
if (envDir !== false) {
1458-
envDir = config.envDir
1459-
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1460-
: resolvedRoot
1461-
}
1462-
1463-
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1464-
1465-
// Note it is possible for user to have a custom mode, e.g. `staging` where
1466-
// development-like behavior is expected. This is indicated by NODE_ENV=development
1467-
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1468-
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1469-
if (!isNodeEnvSet && userNodeEnv) {
1470-
if (userNodeEnv === 'development') {
1471-
process.env.NODE_ENV = 'development'
1472-
} else {
1473-
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1474-
logger.warn(
1475-
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1476-
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1477-
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1478-
)
1479-
}
1480-
}
1481-
1482-
const isProduction = process.env.NODE_ENV === 'production'
1483-
14841452
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
14851453
config.resolve ??= {}
14861454
config.resolve.conditions = config.environments.client.resolve?.conditions
@@ -1496,7 +1464,6 @@ export async function resolveConfig(
14961464
resolvedDefaultResolve.preserveSymlinks,
14971465
inlineConfig.forceOptimizeDeps,
14981466
logger,
1499-
isProduction,
15001467
environmentName,
15011468
config.ssr?.target === 'webworker',
15021469
config.server?.preTransformRequests,
@@ -1521,7 +1488,6 @@ export async function resolveConfig(
15211488
config.build ?? {},
15221489
logger,
15231490
undefined,
1524-
isProduction,
15251491
)
15261492

15271493
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1542,6 +1508,36 @@ export async function resolveConfig(
15421508
resolvedDefaultResolve.preserveSymlinks,
15431509
)
15441510

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

0 commit comments

Comments
 (0)