From e06b90e612520455310a53010dfddc2ce02a569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Tue, 15 Mar 2022 08:34:36 +0800 Subject: [PATCH] support debug --- scripts/watch.mjs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/watch.mjs b/scripts/watch.mjs index d578f53..db84c85 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -2,6 +2,9 @@ import { spawn } from 'child_process' import { createServer, build } from 'vite' import electron from 'electron' +const query = new URLSearchParams(import.meta.url.split('?')[1]) +const debug = query.has('debug') + /** * @type {(server: import('vite').ViteDevServer) => Promise} */ @@ -15,17 +18,21 @@ function watchMain(server) { VITE_DEV_SERVER_HOST: address.address, VITE_DEV_SERVER_PORT: address.port, }) + /** + * @type {import('vite').Plugin} + */ + const startElectron = { + name: 'electron-main-watcher', + writeBundle() { + electronProcess && electronProcess.kill() + electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env }) + }, + } return build({ configFile: 'packages/main/vite.config.ts', mode: 'development', - plugins: [{ - name: 'electron-main-watcher', - writeBundle() { - electronProcess && electronProcess.kill() - electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env }) - }, - }], + plugins: [!debug && startElectron].filter(Boolean), build: { watch: true, },