File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ const { createServer } = require('vite')
3333The ` InlineConfig ` interface extends ` UserConfig ` with additional properties :
3434
3535- ` configFile ` : specify config file to use . If not set , Vite will try to automatically resolve one from project root . Set to ` false ` to disable auto resolving .
36+ - ` envFile ` : Set to ` false ` to disable ` .env ` files .
3637
3738## ` ViteDevServer `
3839
Original file line number Diff line number Diff line change @@ -160,12 +160,13 @@ export interface SSROptions {
160160
161161export interface InlineConfig extends UserConfig {
162162 configFile ?: string | false
163+ envFile ?: false
163164}
164165
165166export type ResolvedConfig = Readonly <
166167 Omit < UserConfig , 'plugins' | 'alias' | 'dedupe' | 'assetsInclude' > & {
167168 configFile : string | undefined
168- inlineConfig : UserConfig
169+ inlineConfig : InlineConfig
169170 root : string
170171 base : string
171172 publicDir : string
@@ -273,7 +274,7 @@ export async function resolveConfig(
273274 }
274275
275276 // load .env files
276- const userEnv = loadEnv ( mode , resolvedRoot )
277+ const userEnv = inlineConfig . envFile !== false && loadEnv ( mode , resolvedRoot )
277278
278279 // Note it is possible for user to have a custom mode, e.g. `staging` where
279280 // production-like behavior is expected. This is indicated by NODE_ENV=production
Original file line number Diff line number Diff line change @@ -44,11 +44,15 @@ export async function handleHMRUpdate(
4444 const { ws, config, moduleGraph } = server
4545 const shortFile = getShortName ( file , config . root )
4646
47- if ( file === config . configFile || file . endsWith ( '.env' ) ) {
47+ const isConfig = file === config . configFile
48+ const isEnv = config . inlineConfig . envFile !== false && file . endsWith ( '.env' )
49+ if ( isConfig || isEnv ) {
4850 // auto restart server
4951 debugHmr ( `[config change] ${ chalk . dim ( shortFile ) } ` )
5052 config . logger . info (
51- chalk . green ( 'config or .env file changed, restarting server...' ) ,
53+ chalk . green (
54+ `${ isConfig ? 'config' : '.env' } file changed, restarting server...`
55+ ) ,
5256 { clear : true , timestamp : true }
5357 )
5458 await restartServer ( server )
You can’t perform that action at this time.
0 commit comments