Skip to content

Commit

Permalink
feat: do not exit when watching build mode (resolve #138)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jun 26, 2022
1 parent 840f831 commit 918c13b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
const overlayConfig = typeof userConfig?.overlay === 'object' ? userConfig?.overlay : null
let resolvedRuntimePath = RUNTIME_PUBLIC_PATH
let checkers: ServeAndBuildChecker[] = []

let viteMode: ConfigEnv['command'] | undefined
let resolvedConfig: ResolvedConfig | undefined

Expand All @@ -58,6 +59,7 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
// for dev mode (1/2)
// Initialize checker with config
viteMode = env.command

checkers = createCheckers(userConfig || {}, env)
if (viteMode !== 'serve') return

Expand Down Expand Up @@ -145,12 +147,9 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
}
},
buildStart: () => {
// for build mode
// only run in build mode
// run a bin command in a separated process
if (viteMode !== 'build') return

// do not do anything when disable build mode
if (!enableBuild) return
if (viteMode !== 'build' || !enableBuild) return

const localEnv = npmRunPath.env({
env: process.env,
Expand All @@ -164,7 +163,10 @@ export default function Plugin(userConfig: UserPluginConfig): Plugin {
checkers.map((checker) => spawnChecker(checker, userConfig, localEnv))
)
const exitCode = exitCodes.find((code) => code !== 0) ?? 0
if (exitCode !== 0) process.exit(exitCode)
// do not exit the process if run `vite build --watch`
if (exitCode !== 0 && !resolvedConfig?.build.watch) {
process.exit(exitCode)
}
})()
},
configureServer(server) {
Expand Down

2 comments on commit 918c13b

@maciejopalinski
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fi3ework
When will this be released as a new version to package manager registry? I really urgently need this fix.

@fi3ework
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PoProstuMieciek Published just now 😉

Please sign in to comment.