@@ -52,6 +52,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
52
52
const overlayConfig = typeof userConfig ?. overlay === 'object' ? userConfig ?. overlay : { }
53
53
let resolvedRuntimePath = RUNTIME_PUBLIC_PATH
54
54
let checkers : ServeAndBuildChecker [ ] = [ ]
55
+ let isProduction = true
56
+ let skipRuntime = false
55
57
56
58
let viteMode : ConfigEnv [ 'command' ] | undefined
57
59
let resolvedConfig : ResolvedConfig | undefined
@@ -80,6 +82,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
80
82
configResolved ( config ) {
81
83
resolvedConfig = config
82
84
resolvedRuntimePath = config . base + RUNTIME_PUBLIC_PATH . slice ( 1 )
85
+ isProduction = config . isProduction
86
+ skipRuntime ||= isProduction || config . command === 'build'
83
87
} ,
84
88
buildEnd ( ) {
85
89
if ( viteMode === 'serve' ) {
@@ -90,19 +94,14 @@ export function checker(userConfig: UserPluginConfig): Plugin {
90
94
}
91
95
} ,
92
96
resolveId ( id ) {
93
- if ( viteMode === 'serve' ) {
94
- if ( id === RUNTIME_PUBLIC_PATH ) {
95
- return id
96
- }
97
+ if ( id === RUNTIME_PUBLIC_PATH ) {
98
+ return id
97
99
}
98
-
99
100
return
100
101
} ,
101
102
load ( id ) {
102
- if ( viteMode === 'serve' ) {
103
- if ( id === RUNTIME_PUBLIC_PATH ) {
104
- return runtimeCode
105
- }
103
+ if ( id === RUNTIME_PUBLIC_PATH ) {
104
+ return runtimeCode
106
105
}
107
106
108
107
return
@@ -141,7 +140,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
141
140
return null
142
141
} ,
143
142
transformIndexHtml ( ) {
144
- if ( viteMode === 'serve' ) {
143
+ if ( ! skipRuntime ) {
145
144
return [
146
145
{
147
146
tag : 'script' ,
@@ -160,7 +159,7 @@ inject({
160
159
buildStart : ( ) => {
161
160
// only run in build mode
162
161
// run a bin command in a separated process
163
- if ( viteMode !== 'build' || ! enableBuild ) return
162
+ if ( ! skipRuntime || ! enableBuild ) return
164
163
165
164
const localEnv = npmRunPath . env ( {
166
165
env : process . env ,
0 commit comments