Skip to content

Commit f107514

Browse files
committed
refactor: add skipRuntime flag
1 parent 5e6318e commit f107514

File tree

1 file changed

+10
-11
lines changed
  • packages/vite-plugin-checker/src

1 file changed

+10
-11
lines changed

packages/vite-plugin-checker/src/main.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
5252
const overlayConfig = typeof userConfig?.overlay === 'object' ? userConfig?.overlay : {}
5353
let resolvedRuntimePath = RUNTIME_PUBLIC_PATH
5454
let checkers: ServeAndBuildChecker[] = []
55+
let isProduction = true
56+
let skipRuntime = false
5557

5658
let viteMode: ConfigEnv['command'] | undefined
5759
let resolvedConfig: ResolvedConfig | undefined
@@ -80,6 +82,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
8082
configResolved(config) {
8183
resolvedConfig = config
8284
resolvedRuntimePath = config.base + RUNTIME_PUBLIC_PATH.slice(1)
85+
isProduction = config.isProduction
86+
skipRuntime ||= isProduction || config.command === 'build'
8387
},
8488
buildEnd() {
8589
if (viteMode === 'serve') {
@@ -90,19 +94,14 @@ export function checker(userConfig: UserPluginConfig): Plugin {
9094
}
9195
},
9296
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
9799
}
98-
99100
return
100101
},
101102
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
106105
}
107106

108107
return
@@ -141,7 +140,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
141140
return null
142141
},
143142
transformIndexHtml() {
144-
if (viteMode === 'serve') {
143+
if (!skipRuntime) {
145144
return [
146145
{
147146
tag: 'script',
@@ -160,7 +159,7 @@ inject({
160159
buildStart: () => {
161160
// only run in build mode
162161
// run a bin command in a separated process
163-
if (viteMode !== 'build' || !enableBuild) return
162+
if (!skipRuntime || !enableBuild) return
164163

165164
const localEnv = npmRunPath.env({
166165
env: process.env,

0 commit comments

Comments
 (0)