File tree 3 files changed +10
-4
lines changed
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')
33
33
The ` InlineConfig ` interface extends ` UserConfig ` with additional properties :
34
34
35
35
- ` 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 .
36
37
37
38
## ` ViteDevServer `
38
39
Original file line number Diff line number Diff line change @@ -160,12 +160,13 @@ export interface SSROptions {
160
160
161
161
export interface InlineConfig extends UserConfig {
162
162
configFile ?: string | false
163
+ envFile ?: false
163
164
}
164
165
165
166
export type ResolvedConfig = Readonly <
166
167
Omit < UserConfig , 'plugins' | 'alias' | 'dedupe' | 'assetsInclude' > & {
167
168
configFile : string | undefined
168
- inlineConfig : UserConfig
169
+ inlineConfig : InlineConfig
169
170
root : string
170
171
base : string
171
172
publicDir : string
@@ -273,7 +274,7 @@ export async function resolveConfig(
273
274
}
274
275
275
276
// load .env files
276
- const userEnv = loadEnv ( mode , resolvedRoot )
277
+ const userEnv = inlineConfig . envFile !== false && loadEnv ( mode , resolvedRoot )
277
278
278
279
// Note it is possible for user to have a custom mode, e.g. `staging` where
279
280
// 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(
44
44
const { ws, config, moduleGraph } = server
45
45
const shortFile = getShortName ( file , config . root )
46
46
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 ) {
48
50
// auto restart server
49
51
debugHmr ( `[config change] ${ chalk . dim ( shortFile ) } ` )
50
52
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
+ ) ,
52
56
{ clear : true , timestamp : true }
53
57
)
54
58
await restartServer ( server )
You can’t perform that action at this time.
0 commit comments