Skip to content

Commit 30f1edc

Browse files
committed
Revert "feat: disable minify by default in development"
This reverts commit 2af81b7.
1 parent 99b8d05 commit 30f1edc

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
@@ -812,7 +812,6 @@ function resolveEnvironmentOptions(
812812
preserveSymlinks: boolean,
813813
forceOptimizeDeps: boolean | undefined,
814814
logger: Logger,
815-
isProduction: boolean,
816815
environmentName: string,
817816
// Backward compatibility
818817
isSsrTargetWebworkerSet?: boolean,
@@ -876,7 +875,6 @@ function resolveEnvironmentOptions(
876875
options.build ?? {},
877876
logger,
878877
consumer,
879-
isProduction,
880878
),
881879
plugins: undefined!, // to be resolved later
882880
// will be set by `setOptimizeDepsPluginNames` later
@@ -1446,36 +1444,6 @@ export async function resolveConfig(
14461444
config.ssr?.target === 'webworker',
14471445
)
14481446

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-
14791447
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
14801448
config.resolve ??= {}
14811449
config.resolve.conditions = config.environments.client.resolve?.conditions
@@ -1491,7 +1459,6 @@ export async function resolveConfig(
14911459
resolvedDefaultResolve.preserveSymlinks,
14921460
inlineConfig.forceOptimizeDeps,
14931461
logger,
1494-
isProduction,
14951462
environmentName,
14961463
config.ssr?.target === 'webworker',
14971464
config.server?.preTransformRequests,
@@ -1516,7 +1483,6 @@ export async function resolveConfig(
15161483
config.build ?? {},
15171484
logger,
15181485
undefined,
1519-
isProduction,
15201486
)
15211487

15221488
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1537,6 +1503,36 @@ export async function resolveConfig(
15371503
resolvedDefaultResolve.preserveSymlinks,
15381504
)
15391505

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+
15401536
// resolve public base url
15411537
const relativeBaseShortcut = config.base === '' || config.base === './'
15421538

0 commit comments

Comments
 (0)