@@ -12,7 +12,7 @@ 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 = config . mode === 'production '
1616 const isBuildLib = config . build . lib
1717
1818 // ignore replace process.env in lib build
@@ -33,17 +33,17 @@ export function definePlugin(config: ResolvedConfig): Plugin {
3333 const importMetaKeys : Record < string , string > = { }
3434 const importMetaEnvKeys : Record < string , string > = { }
3535 const importMetaFallbackKeys : Record < string , string > = { }
36- // if (isBuild) {
37- importMetaKeys [ 'import.meta.hot' ] = `undefined`
38- for ( const key in config . env ) {
39- const val = JSON . stringify ( config . env [ key ] )
40- importMetaKeys [ `import.meta.env.${ key } ` ] = val
41- importMetaEnvKeys [ key ] = val
36+ if ( isBuild ) {
37+ importMetaKeys [ 'import.meta.hot' ] = `undefined`
38+ for ( const key in config . env ) {
39+ const val = JSON . stringify ( config . env [ key ] )
40+ importMetaKeys [ `import.meta.env.${ key } ` ] = val
41+ importMetaEnvKeys [ key ] = val
42+ }
43+ // these will be set to a proper value in `generatePattern`
44+ importMetaKeys [ 'import.meta.env.SSR' ] = `undefined`
45+ importMetaFallbackKeys [ 'import.meta.env' ] = `undefined`
4246 }
43- // these will be set to a proper value in `generatePattern`
44- importMetaKeys [ 'import.meta.env.SSR' ] = `undefined`
45- importMetaFallbackKeys [ 'import.meta.env' ] = `undefined`
46- // }
4747
4848 function generatePattern ( environment : Environment ) {
4949 const keepProcessEnv = environment . config . keepProcessEnv
0 commit comments