From d4f6e2c621b67c0e9d5ea8e9876b5290f73f8998 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 15 Jun 2022 11:19:27 +1000 Subject: [PATCH 1/2] Display errors on exit --- src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 92d0738..1283ae0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,13 +134,21 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl if (fs.existsSync(hotFile)) { fs.rmSync(hotFile) } - process.exit() } process.on('exit', clean) - process.on('SIGHUP', clean) - process.on('SIGINT', clean) - process.on('SIGTERM', clean) + process.on('SIGHUP', () => { + clean() + process.exit() + }) + process.on('SIGINT', () => { + clean() + process.exit() + }) + process.on('SIGTERM', () => { + clean() + process.exit() + }) }, // The following two hooks are a workaround to help solve a "flash of unstyled content" with Blade. From dc8d7b9e362cf615570f422563233d26532c3163 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 15 Jun 2022 12:26:53 +1000 Subject: [PATCH 2/2] Ensure listeners aren't bound multiple times --- src/index.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1283ae0..7f03a18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,6 +41,8 @@ interface LaravelPlugin extends Plugin { config: (config: UserConfig, env: ConfigEnv) => UserConfig } +let exitHandlersBound = false + /** * Laravel plugin for Vite. * @@ -130,6 +132,10 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl } }) + if (exitHandlersBound) { + return + } + const clean = () => { if (fs.existsSync(hotFile)) { fs.rmSync(hotFile) @@ -137,18 +143,11 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl } process.on('exit', clean) - process.on('SIGHUP', () => { - clean() - process.exit() - }) - process.on('SIGINT', () => { - clean() - process.exit() - }) - process.on('SIGTERM', () => { - clean() - process.exit() - }) + process.on('SIGINT', process.exit) + process.on('SIGTERM', process.exit) + process.on('SIGHUP', process.exit) + + exitHandlersBound = true }, // The following two hooks are a workaround to help solve a "flash of unstyled content" with Blade.