From 8a4cfd2aa13611aadfd18844e54b90399e669003 Mon Sep 17 00:00:00 2001 From: Parmesh Krishen Date: Fri, 24 Jul 2020 12:31:44 -0500 Subject: [PATCH] fix: shutdown dev server on fatal error (#143) * Fix dev server restart error * chore: apply review changes Co-authored-by: Luke Edwards --- rollup.config.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index ce3c9eb..6a95234 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,6 +6,27 @@ import { terser } from 'rollup-plugin-terser'; const production = !process.env.ROLLUP_WATCH; +function serve() { + let server; + + function toExit() { + if (server) server.kill(0); + } + + return { + writeBundle() { + if (server) return; + server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { + stdio: ['ignore', 'inherit', 'inherit'], + shell: true + }); + + process.on('SIGTERM', toExit); + process.on('exit', toExit); + } + }; +} + export default { input: 'src/main.js', output: { @@ -52,20 +73,3 @@ export default { clearScreen: false } }; - -function serve() { - let started = false; - - return { - writeBundle() { - if (!started) { - started = true; - - require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { - stdio: ['ignore', 'inherit', 'inherit'], - shell: true - }); - } - } - }; -}