Great answer https://stackoverflow.com/a/76920975/14600377
And this is for SvelteKit if someone needs
function closeBundle(): Plugin {
let vite_config: ResolvedConfig
return {
name: 'ClosePlugin',
configResolved(config) {
vite_config = config;
},
closeBundle: {
sequential: true,
async handler() {
if (!vite_config.build.ssr) return;
process.exit(0)
}
}
}
}