@@ -12,7 +12,8 @@ const importMetaEnvMarker = '__vite_import_meta_env__'
1212const importMetaEnvKeyReCache = new Map < string , RegExp > ( )
1313
1414export function definePlugin ( config : ResolvedConfig ) : Plugin {
15- const isBuild = config . command === 'build'
15+ const isBuild =
16+ config . command === 'build' || ! ! config . experimental . fullBundleMode
1617 const isBuildLib = isBuild && config . build . lib
1718
1819 // ignore replace process.env in lib build
@@ -33,8 +34,11 @@ export function definePlugin(config: ResolvedConfig): Plugin {
3334 const importMetaKeys : Record < string , string > = { }
3435 const importMetaEnvKeys : Record < string , string > = { }
3536 const importMetaFallbackKeys : Record < string , string > = { }
36- if ( isBuild && ! config . experimental . fullBundleMode ) {
37- importMetaKeys [ 'import.meta.hot' ] = `undefined`
37+ if ( isBuild ) {
38+ // import.meta.hot need to avoid replace undefined at full bundle mode
39+ if ( ! config . experimental . fullBundleMode ) {
40+ importMetaKeys [ 'import.meta.hot' ] = `undefined`
41+ }
3842 for ( const key in config . env ) {
3943 const val = JSON . stringify ( config . env [ key ] )
4044 importMetaKeys [ `import.meta.env.${ key } ` ] = val
@@ -54,11 +58,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
5458 userDefine [ key ] = handleDefineValue ( environment . config . define [ key ] )
5559
5660 // make sure `import.meta.env` object has user define properties
57- if (
58- isBuild &&
59- ! config . experimental . fullBundleMode &&
60- key . startsWith ( 'import.meta.env.' )
61- ) {
61+ if ( isBuild && key . startsWith ( 'import.meta.env.' ) ) {
6262 userDefineEnv [ key . slice ( 16 ) ] = environment . config . define [ key ]
6363 }
6464 }
@@ -132,11 +132,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
132132
133133 transform : {
134134 async handler ( code , id ) {
135- if (
136- this . environment . config . consumer === 'client' &&
137- ! isBuild &&
138- ! config . experimental . fullBundleMode
139- ) {
135+ if ( this . environment . config . consumer === 'client' && ! isBuild ) {
140136 // for dev we inject actual global defines in the vite client to
141137 // avoid the transform cost. see the `clientInjection` and
142138 // `importAnalysis` plugin.
0 commit comments