File tree 4 files changed +20
-4
lines changed
packages/vite/src/node/plugins
4 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
85
85
. join ( '|' ) +
86
86
// Mustn't be followed by a char that can be part of an identifier
87
87
// or an assignment (but allow equality operators)
88
- ')(?![\\p{L}\\p{N}_$]|\\s*?=[^=])' ,
88
+ ')(?:(?<=\\.)|(? ![\\p{L}\\p{N}_$]|\\s*?=[^=]) )' ,
89
89
'gu'
90
90
)
91
91
: null
Original file line number Diff line number Diff line change 1
1
import { expect , test } from 'vitest'
2
2
import viteConfig from '../vite.config'
3
- import { page } from '~utils'
3
+ import { isBuild , page } from '~utils'
4
4
5
5
test ( 'string' , async ( ) => {
6
6
const defines = viteConfig . define
@@ -44,4 +44,10 @@ test('string', async () => {
44
44
expect ( await page . textContent ( '.define-in-dep' ) ) . toBe (
45
45
defines . __STRINGIFIED_OBJ__
46
46
)
47
+ expect ( await page . textContent ( '.import-meta-env-undefined' ) ) . toBe (
48
+ isBuild ? '({}).UNDEFINED' : 'import.meta.env.UNDEFINED'
49
+ )
50
+ expect ( await page . textContent ( '.process-env-undefined' ) ) . toBe (
51
+ isBuild ? '({}).UNDEFINED' : 'process.env.UNDEFINED'
52
+ )
47
53
} )
Original file line number Diff line number Diff line change 1
- module . exports = { defined : __STRINGIFIED_OBJ__ }
1
+ module . exports = {
2
+ defined : __STRINGIFIED_OBJ__ ,
3
+ importMetaEnvUndefined : 'import.meta.env.UNDEFINED' ,
4
+ processEnvUndefined : 'process.env.UNDEFINED'
5
+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ <h1>Define</h1>
17
17
< p > define variable in html: < code class ="exp-define "> __EXP__</ code > </ p >
18
18
< p > import json: < code class ="import-json "> </ code > </ p >
19
19
< p > define in dep: < code class ="define-in-dep "> </ code > </ p >
20
+ < p >
21
+ import.meta.env.UNDEFINED: < code class ="import-meta-env-undefined "> </ code >
22
+ </ p >
23
+ < p > process.env.UNDEFINED: < code class ="process-env-undefined "> </ code > </ p >
20
24
21
25
< script type ="module ">
22
26
const __VAR_NAME__ = true // ensure define doesn't replace var name
@@ -52,8 +56,10 @@ <h1>Define</h1>
52
56
document . querySelector ( el ) . textContent = text
53
57
}
54
58
55
- import { defined } from 'dep'
59
+ import { defined , importMetaEnvUndefined , processEnvUndefined } from 'dep'
56
60
text ( '.define-in-dep' , JSON . stringify ( defined ) )
61
+ text ( '.import-meta-env-undefined' , importMetaEnvUndefined )
62
+ text ( '.process-env-undefined' , processEnvUndefined )
57
63
</ script >
58
64
59
65
< style >
You can’t perform that action at this time.
0 commit comments