From 66db8babbfbf1f92cdfdd39e990842c2ea5f684d Mon Sep 17 00:00:00 2001 From: April Hall Date: Tue, 11 Feb 2025 14:23:42 -0500 Subject: [PATCH] fix: Build stage stalling Build stage would stall after finishing, this could cause some issue when containerization is implemented, so I wrote a vite plugin to auto kill it after it finished bundling. --- src/lib/functions/autoCloseViteBuild.ts | 23 +++++++++++++++++++++++ vite.config.ts | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 src/lib/functions/autoCloseViteBuild.ts diff --git a/src/lib/functions/autoCloseViteBuild.ts b/src/lib/functions/autoCloseViteBuild.ts new file mode 100644 index 0000000..6079622 --- /dev/null +++ b/src/lib/functions/autoCloseViteBuild.ts @@ -0,0 +1,23 @@ +import type { PluginOption } from 'vite'; + +export default function closePlugin() { + const plugin: PluginOption = { + name: 'BuildWatcher', + buildEnd: function (error?: Error) { + if (error) { + console.error('\x1b[35m[BuildWatcher]\x1b[0m Error building.'); + console.error(error); + process.exit(1); + } else { + console.log('\x1b[35m[BuildWatcher]\x1b[0m Build Stage Ended.'); + } + }, + + closeBundle: function () { + console.log('\x1b[35m[BuildWatcher]\x1b[0m Bundle closed'); + process.exit(0); + }, + }; + + return plugin; +} diff --git a/vite.config.ts b/vite.config.ts index 5f91bb8..41c30ec 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,10 +1,12 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; import { startupSocketIOServer } from './src/lib/functions/websocketConfig'; +import closePlugin from './src/lib/functions/autoCloseViteBuild'; export default defineConfig({ plugins: [ sveltekit(), + closePlugin(), { name: 'integratedSocketIOServer', configureServer(server) {