@@ -58,6 +58,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
58
58
const enableOverlay = userConfig ?. overlay !== false
59
59
const enableTerminal = userConfig ?. terminal !== false
60
60
const overlayConfig = typeof userConfig ?. overlay === 'object' ? userConfig ?. overlay : { }
61
+ let initialized = false
62
+ let initializeCounter = 0
61
63
let checkers : ServeAndBuildChecker [ ] = [ ]
62
64
let isProduction = true
63
65
let skipRuntime = false
@@ -75,6 +77,13 @@ export function checker(userConfig: UserPluginConfig): Plugin {
75
77
// for dev mode (1/2)
76
78
// Initialize checker with config
77
79
viteMode = env . command
80
+ // avoid running twice when running in SSR
81
+ if ( initializeCounter === 0 ) {
82
+ initializeCounter ++
83
+ } else {
84
+ initialized = true
85
+ return
86
+ }
78
87
79
88
checkers = await createCheckers ( userConfig || { } , env )
80
89
if ( viteMode !== 'serve' ) return
@@ -95,6 +104,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
95
104
skipRuntime ||= isProduction || config . command === 'build'
96
105
} ,
97
106
buildEnd ( ) {
107
+ if ( initialized ) return
108
+
98
109
if ( viteMode === 'serve' ) {
99
110
checkers . forEach ( ( checker ) => {
100
111
const { worker } = checker . serve
@@ -121,19 +132,19 @@ export function checker(userConfig: UserPluginConfig): Plugin {
121
132
return
122
133
} ,
123
134
transformIndexHtml ( ) {
124
- if ( ! skipRuntime ) {
125
- return [
126
- {
127
- tag : 'script' ,
128
- attrs : { type : 'module' } ,
129
- children : composePreambleCode ( resolvedConfig ! . base , overlayConfig ) ,
130
- } ,
131
- ]
132
- }
133
-
134
- return
135
+ if ( initialized ) return
136
+ if ( skipRuntime ) return
137
+
138
+ return [
139
+ {
140
+ tag : 'script' ,
141
+ attrs : { type : 'module' } ,
142
+ children : composePreambleCode ( resolvedConfig ! . base , overlayConfig ) ,
143
+ } ,
144
+ ]
135
145
} ,
136
146
buildStart : ( ) => {
147
+ if ( initialized ) return
137
148
// only run in build mode
138
149
// run a bin command in a separated process
139
150
if ( ! skipRuntime || ! enableBuild ) return
@@ -157,6 +168,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
157
168
} ) ( )
158
169
} ,
159
170
configureServer ( server ) {
171
+ if ( initialized ) return
172
+
160
173
let latestOverlayErrors : ClientReconnectPayload [ 'data' ] = new Array ( checkers . length )
161
174
// for dev mode (2/2)
162
175
// Get the server instance and keep reference in a closure
0 commit comments