Skip to content

Commit 9b74d44

Browse files
authored
Merge pull request #17 from laravel/graceful-exit
Display errors on exit
2 parents 3e4dbd2 + dc8d7b9 commit 9b74d44

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface LaravelPlugin extends Plugin {
4141
config: (config: UserConfig, env: ConfigEnv) => UserConfig
4242
}
4343

44+
let exitHandlersBound = false
45+
4446
/**
4547
* Laravel plugin for Vite.
4648
*
@@ -130,17 +132,22 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl
130132
}
131133
})
132134

135+
if (exitHandlersBound) {
136+
return
137+
}
138+
133139
const clean = () => {
134140
if (fs.existsSync(hotFile)) {
135141
fs.rmSync(hotFile)
136142
}
137-
process.exit()
138143
}
139144

140145
process.on('exit', clean)
141-
process.on('SIGHUP', clean)
142-
process.on('SIGINT', clean)
143-
process.on('SIGTERM', clean)
146+
process.on('SIGINT', process.exit)
147+
process.on('SIGTERM', process.exit)
148+
process.on('SIGHUP', process.exit)
149+
150+
exitHandlersBound = true
144151
},
145152

146153
// The following two hooks are a workaround to help solve a "flash of unstyled content" with Blade.

0 commit comments

Comments
 (0)