Skip to content

Commit

Permalink
refactor: add skipRuntime flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jan 1, 2023
1 parent 5e6318e commit f107514
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
const overlayConfig = typeof userConfig?.overlay === 'object' ? userConfig?.overlay : {}
let resolvedRuntimePath = RUNTIME_PUBLIC_PATH
let checkers: ServeAndBuildChecker[] = []
let isProduction = true
let skipRuntime = false

let viteMode: ConfigEnv['command'] | undefined
let resolvedConfig: ResolvedConfig | undefined
Expand Down Expand Up @@ -80,6 +82,8 @@ export function checker(userConfig: UserPluginConfig): Plugin {
configResolved(config) {
resolvedConfig = config
resolvedRuntimePath = config.base + RUNTIME_PUBLIC_PATH.slice(1)
isProduction = config.isProduction
skipRuntime ||= isProduction || config.command === 'build'
},
buildEnd() {
if (viteMode === 'serve') {
Expand All @@ -90,19 +94,14 @@ export function checker(userConfig: UserPluginConfig): Plugin {
}
},
resolveId(id) {
if (viteMode === 'serve') {
if (id === RUNTIME_PUBLIC_PATH) {
return id
}
if (id === RUNTIME_PUBLIC_PATH) {
return id
}

return
},
load(id) {
if (viteMode === 'serve') {
if (id === RUNTIME_PUBLIC_PATH) {
return runtimeCode
}
if (id === RUNTIME_PUBLIC_PATH) {
return runtimeCode
}

return
Expand Down Expand Up @@ -141,7 +140,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
return null
},
transformIndexHtml() {
if (viteMode === 'serve') {
if (!skipRuntime) {
return [
{
tag: 'script',
Expand All @@ -160,7 +159,7 @@ inject({
buildStart: () => {
// only run in build mode
// run a bin command in a separated process
if (viteMode !== 'build' || !enableBuild) return
if (!skipRuntime || !enableBuild) return

const localEnv = npmRunPath.env({
env: process.env,
Expand Down

0 comments on commit f107514

Please sign in to comment.