Skip to content

Commit dc8d7b9

Browse files
committed
Ensure listeners aren't bound multiple times
1 parent d4f6e2c commit dc8d7b9

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/index.ts

Lines changed: 11 additions & 12 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,25 +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
}
137143
}
138144

139145
process.on('exit', clean)
140-
process.on('SIGHUP', () => {
141-
clean()
142-
process.exit()
143-
})
144-
process.on('SIGINT', () => {
145-
clean()
146-
process.exit()
147-
})
148-
process.on('SIGTERM', () => {
149-
clean()
150-
process.exit()
151-
})
146+
process.on('SIGINT', process.exit)
147+
process.on('SIGTERM', process.exit)
148+
process.on('SIGHUP', process.exit)
149+
150+
exitHandlersBound = true
152151
},
153152

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

0 commit comments

Comments
 (0)