Skip to content

Commit 090a5ca

Browse files
committed
Revert "feat: disable minify by default in development"
This reverts commit 2af81b7.
1 parent 6790883 commit 090a5ca

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
@@ -407,7 +407,6 @@ export function resolveBuildEnvironmentOptions(
407407
raw: BuildEnvironmentOptions,
408408
logger: Logger,
409409
consumer: 'client' | 'server' | undefined,
410-
isProduction: boolean,
411410
): ResolvedBuildEnvironmentOptions {
412411
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload
413412
const { polyfillModulePreload, ...rest } = raw
@@ -428,7 +427,7 @@ export function resolveBuildEnvironmentOptions(
428427
{
429428
...buildEnvironmentOptionsDefaults,
430429
cssCodeSplit: !raw.lib,
431-
minify: !isProduction || consumer === 'server' ? false : 'oxc',
430+
minify: consumer === 'server' ? false : 'oxc',
432431
rollupOptions: {},
433432
rolldownOptions: undefined,
434433
ssr: consumer === 'server',

packages/vite/src/node/config.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ function resolveEnvironmentOptions(
838838
preserveSymlinks: boolean,
839839
forceOptimizeDeps: boolean | undefined,
840840
logger: Logger,
841-
isProduction: boolean,
842841
environmentName: string,
843842
// Backward compatibility
844843
isSsrTargetWebworkerSet?: boolean,
@@ -902,7 +901,6 @@ function resolveEnvironmentOptions(
902901
options.build ?? {},
903902
logger,
904903
consumer,
905-
isProduction,
906904
),
907905
plugins: undefined!, // to be resolved later
908906
// will be set by `setOptimizeDepsPluginNames` later
@@ -1487,36 +1485,6 @@ export async function resolveConfig(
14871485
config.ssr?.target === 'webworker',
14881486
)
14891487

1490-
// load .env files
1491-
// Backward compatibility: set envDir to false when envFile is false
1492-
let envDir = config.envFile === false ? false : config.envDir
1493-
if (envDir !== false) {
1494-
envDir = config.envDir
1495-
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1496-
: resolvedRoot
1497-
}
1498-
1499-
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1500-
1501-
// Note it is possible for user to have a custom mode, e.g. `staging` where
1502-
// development-like behavior is expected. This is indicated by NODE_ENV=development
1503-
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1504-
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1505-
if (!isNodeEnvSet && userNodeEnv) {
1506-
if (userNodeEnv === 'development') {
1507-
process.env.NODE_ENV = 'development'
1508-
} else {
1509-
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1510-
logger.warn(
1511-
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1512-
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1513-
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1514-
)
1515-
}
1516-
}
1517-
1518-
const isProduction = process.env.NODE_ENV === 'production'
1519-
15201488
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
15211489
config.resolve ??= {}
15221490
config.resolve.conditions = config.environments.client.resolve?.conditions
@@ -1532,7 +1500,6 @@ export async function resolveConfig(
15321500
resolvedDefaultResolve.preserveSymlinks,
15331501
inlineConfig.forceOptimizeDeps,
15341502
logger,
1535-
isProduction,
15361503
environmentName,
15371504
config.ssr?.target === 'webworker',
15381505
config.server?.preTransformRequests,
@@ -1557,7 +1524,6 @@ export async function resolveConfig(
15571524
config.build ?? {},
15581525
logger,
15591526
undefined,
1560-
isProduction,
15611527
)
15621528

15631529
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1578,6 +1544,36 @@ export async function resolveConfig(
15781544
resolvedDefaultResolve.preserveSymlinks,
15791545
)
15801546

1547+
// load .env files
1548+
// Backward compatibility: set envDir to false when envFile is false
1549+
let envDir = config.envFile === false ? false : config.envDir
1550+
if (envDir !== false) {
1551+
envDir = config.envDir
1552+
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1553+
: resolvedRoot
1554+
}
1555+
1556+
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1557+
1558+
// Note it is possible for user to have a custom mode, e.g. `staging` where
1559+
// development-like behavior is expected. This is indicated by NODE_ENV=development
1560+
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1561+
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1562+
if (!isNodeEnvSet && userNodeEnv) {
1563+
if (userNodeEnv === 'development') {
1564+
process.env.NODE_ENV = 'development'
1565+
} else {
1566+
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1567+
logger.warn(
1568+
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1569+
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1570+
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1571+
)
1572+
}
1573+
}
1574+
1575+
const isProduction = process.env.NODE_ENV === 'production'
1576+
15811577
// resolve public base url
15821578
const relativeBaseShortcut = config.base === '' || config.base === './'
15831579

0 commit comments

Comments
 (0)