Skip to content

Instantly share code, notes, and snippets.

@schickling
Created May 15, 2025 07:34
  • Select an option

Select an option

Revisions

  1. schickling created this gist May 15, 2025.
    27 changes: 27 additions & 0 deletions dev-vite-wrangler.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    import { spawn } from 'node:child_process'
    import process from 'node:process'

    const run = (cmd: string, args: string[], forwardStdin = true) =>
    spawn(cmd, args, {
    shell: true,
    stdio: [forwardStdin ? 'inherit' : 'ignore', 'inherit', 'inherit'],
    })

    const processes = [
    // Forward stdin to allow Vite keyboard input
    run('pnpm', ['run', 'dev:vite'], true),
    run('pnpm', ['run', 'dev:wrangler'], false),
    ]

    // Cleanly kill both on ^C or when either exits
    const shutdown = () => {
    for (const p of processes) {
    p.kill('SIGINT')
    }
    }

    process.on('SIGINT', shutdown).on('SIGTERM', shutdown)

    for (const p of processes) {
    p.on('exit', shutdown)
    }