Skip to content

Commit 422fbc4

Browse files
committed
Revert "feat: disable minify by default in development"
This reverts commit 2af81b7.
1 parent dbf4ee2 commit 422fbc4

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
@@ -401,7 +401,6 @@ export function resolveBuildEnvironmentOptions(
401401
raw: BuildEnvironmentOptions,
402402
logger: Logger,
403403
consumer: 'client' | 'server' | undefined,
404-
isProduction: boolean,
405404
): ResolvedBuildEnvironmentOptions {
406405
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload
407406
const { polyfillModulePreload, ...rest } = raw
@@ -422,7 +421,7 @@ export function resolveBuildEnvironmentOptions(
422421
{
423422
...buildEnvironmentOptionsDefaults,
424423
cssCodeSplit: !raw.lib,
425-
minify: !isProduction || consumer === 'server' ? false : 'oxc',
424+
minify: consumer === 'server' ? false : 'oxc',
426425
rollupOptions: {
427426
platform: consumer === 'server' ? 'node' : 'browser',
428427
},

packages/vite/src/node/config.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ function resolveEnvironmentOptions(
824824
preserveSymlinks: boolean,
825825
forceOptimizeDeps: boolean | undefined,
826826
logger: Logger,
827-
isProduction: boolean,
828827
environmentName: string,
829828
// Backward compatibility
830829
isSsrTargetWebworkerSet?: boolean,
@@ -888,7 +887,6 @@ function resolveEnvironmentOptions(
888887
options.build ?? {},
889888
logger,
890889
consumer,
891-
isProduction,
892890
),
893891
plugins: undefined!, // to be resolved later
894892
// will be set by `setOptimizeDepsPluginNames` later
@@ -1458,36 +1456,6 @@ export async function resolveConfig(
14581456
config.ssr?.target === 'webworker',
14591457
)
14601458

1461-
// load .env files
1462-
// Backward compatibility: set envDir to false when envFile is false
1463-
let envDir = config.envFile === false ? false : config.envDir
1464-
if (envDir !== false) {
1465-
envDir = config.envDir
1466-
? normalizePath(path.resolve(resolvedRoot, config.envDir))
1467-
: resolvedRoot
1468-
}
1469-
1470-
const userEnv = loadEnv(mode, envDir, resolveEnvPrefix(config))
1471-
1472-
// Note it is possible for user to have a custom mode, e.g. `staging` where
1473-
// development-like behavior is expected. This is indicated by NODE_ENV=development
1474-
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
1475-
const userNodeEnv = process.env.VITE_USER_NODE_ENV
1476-
if (!isNodeEnvSet && userNodeEnv) {
1477-
if (userNodeEnv === 'development') {
1478-
process.env.NODE_ENV = 'development'
1479-
} else {
1480-
// NODE_ENV=production is not supported as it could break HMR in dev for frameworks like Vue
1481-
logger.warn(
1482-
`NODE_ENV=${userNodeEnv} is not supported in the .env file. ` +
1483-
`Only NODE_ENV=development is supported to create a development build of your project. ` +
1484-
`If you need to set process.env.NODE_ENV, you can set it in the Vite config instead.`,
1485-
)
1486-
}
1487-
}
1488-
1489-
const isProduction = process.env.NODE_ENV === 'production'
1490-
14911459
// Backward compatibility: merge config.environments.client.resolve back into config.resolve
14921460
config.resolve ??= {}
14931461
config.resolve.conditions = config.environments.client.resolve?.conditions
@@ -1503,7 +1471,6 @@ export async function resolveConfig(
15031471
resolvedDefaultResolve.preserveSymlinks,
15041472
inlineConfig.forceOptimizeDeps,
15051473
logger,
1506-
isProduction,
15071474
environmentName,
15081475
config.ssr?.target === 'webworker',
15091476
config.server?.preTransformRequests,
@@ -1528,7 +1495,6 @@ export async function resolveConfig(
15281495
config.build ?? {},
15291496
logger,
15301497
undefined,
1531-
isProduction,
15321498
)
15331499

15341500
// Backward compatibility: merge config.environments.ssr back into config.ssr
@@ -1549,6 +1515,36 @@ export async function resolveConfig(
15491515
resolvedDefaultResolve.preserveSymlinks,
15501516
)
15511517

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

0 commit comments

Comments
 (0)