From 6025ef1eb5b3547a07dfed78d52f1863f3261e3b Mon Sep 17 00:00:00 2001 From: Josh Wooding <12938082+joshwooding@users.noreply.github.com> Date: Sat, 8 Oct 2022 19:39:23 +0100 Subject: [PATCH] Fix bail not being defined for the vite builder --- code/lib/builder-vite/src/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/code/lib/builder-vite/src/index.ts b/code/lib/builder-vite/src/index.ts index bb3b5dc1f98b..d72243c5130a 100644 --- a/code/lib/builder-vite/src/index.ts +++ b/code/lib/builder-vite/src/index.ts @@ -57,13 +57,25 @@ function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): Requ }; } +let server: ViteDevServer; + +export async function bail(e?: Error): Promise { + try { + return await server.close(); + } catch (err) { + console.warn('unable to close vite server'); + } + + throw e; +} + export const start: ViteBuilder['start'] = async ({ startTime, options, router, server: devServer, }) => { - const server = await createViteServer(options as ExtendedOptions, devServer); + server = await createViteServer(options as ExtendedOptions, devServer); // Just mock this endpoint (which is really Webpack-specific) so we don't get spammed with 404 in browser devtools // TODO: we should either show some sort of progress from Vite, or just try to disable the whole Loader in the Manager UI. @@ -75,16 +87,6 @@ export const start: ViteBuilder['start'] = async ({ router.use(iframeMiddleware(options as ExtendedOptions, server)); router.use(server.middlewares); - async function bail(e?: Error): Promise { - try { - return await server.close(); - } catch (err) { - console.warn('unable to close vite server'); - } - - throw e; - } - return { bail, stats: { toJson: () => null },