Skip to content

Commit

Permalink
Merge pull request #17 from laravel/graceful-exit
Browse files Browse the repository at this point in the history
Display errors on exit
  • Loading branch information
jessarcher authored Jun 15, 2022
2 parents 3e4dbd2 + dc8d7b9 commit 9b74d44
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface LaravelPlugin extends Plugin {
config: (config: UserConfig, env: ConfigEnv) => UserConfig
}

let exitHandlersBound = false

/**
* Laravel plugin for Vite.
*
Expand Down Expand Up @@ -130,17 +132,22 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl
}
})

if (exitHandlersBound) {
return
}

const clean = () => {
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('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.
Expand Down

0 comments on commit 9b74d44

Please sign in to comment.