Skip to content

Commit c575b82

Browse files
authored
feat: show mode on server start and add env debugger (#18808)
1 parent 73987f2 commit c575b82

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/vite/src/node/cli.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ cli
201201

202202
const info = server.config.logger.info
203203

204+
const modeString =
205+
options.mode && options.mode !== 'development'
206+
? ` ${colors.bgGreen(` ${colors.bold(options.mode)} `)}`
207+
: ''
204208
const viteStartTime = global.__vite_start_time ?? false
205209
const startupDurationString = viteStartTime
206210
? colors.dim(
@@ -215,7 +219,7 @@ cli
215219
info(
216220
`\n ${colors.green(
217221
`${colors.bold('VITE')} v${VERSION}`,
218-
)} ${startupDurationString}\n`,
222+
)}${modeString} ${startupDurationString}\n`,
219223
{
220224
clear: !hasExistingLogs,
221225
},

packages/vite/src/node/env.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import fs from 'node:fs'
22
import path from 'node:path'
33
import { parse } from 'dotenv'
44
import { type DotenvPopulateInput, expand } from 'dotenv-expand'
5-
import { arraify, normalizePath, tryStatSync } from './utils'
5+
import { arraify, createDebugger, normalizePath, tryStatSync } from './utils'
66
import type { UserConfig } from './config'
77

8+
const debug = createDebugger('vite:env')
9+
810
export function getEnvFilesForMode(mode: string, envDir: string): string[] {
911
return [
1012
/** default file */ `.env`,
@@ -19,6 +21,9 @@ export function loadEnv(
1921
envDir: string,
2022
prefixes: string | string[] = 'VITE_',
2123
): Record<string, string> {
24+
const start = performance.now()
25+
const getTime = () => `${(performance.now() - start).toFixed(2)}ms`
26+
2227
if (mode === 'local') {
2328
throw new Error(
2429
`"local" cannot be used as a mode name because it conflicts with ` +
@@ -29,6 +34,8 @@ export function loadEnv(
2934
const env: Record<string, string> = {}
3035
const envFiles = getEnvFilesForMode(mode, envDir)
3136

37+
debug?.(`loading env files: %O`, envFiles)
38+
3239
const parsed = Object.fromEntries(
3340
envFiles.flatMap((filePath) => {
3441
if (!tryStatSync(filePath)?.isFile()) return []
@@ -37,6 +44,8 @@ export function loadEnv(
3744
}),
3845
)
3946

47+
debug?.(`env files loaded in ${getTime()}`)
48+
4049
// test NODE_ENV override before expand as otherwise process.env.NODE_ENV would override this
4150
if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === undefined) {
4251
process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV
@@ -69,6 +78,8 @@ export function loadEnv(
6978
}
7079
}
7180

81+
debug?.(`using resolved env: %O`, env)
82+
7283
return env
7384
}
7485

0 commit comments

Comments
 (0)