From ebb226e917cced4ba16e4f6d610dc97c136232ca 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: Thu, 25 Aug 2022 08:29:44 +0800 Subject: [PATCH] refactor: better Debug --- .vscode/.debug.script.mjs | 2 +- electron/main/index.ts | 3 +-- package.json | 9 ++++++--- vite.config.ts | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.vscode/.debug.script.mjs b/.vscode/.debug.script.mjs index 1d68c8f..2066b94 100644 --- a/.vscode/.debug.script.mjs +++ b/.vscode/.debug.script.mjs @@ -8,7 +8,7 @@ const pkg = createRequire(import.meta.url)('../package.json') const __dirname = path.dirname(fileURLToPath(import.meta.url)) // write .debug.env -const envContent = Object.entries(pkg.env).map(([key, val]) => `${key}=${val}`) +const envContent = Object.entries(pkg.debug.env).map(([key, val]) => `${key}=${val}`) fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n')) // bootstrap diff --git a/electron/main/index.ts b/electron/main/index.ts index 70f0e30..ddeb673 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -28,8 +28,7 @@ export const ROOT_PATH = { let win: BrowserWindow | null = null // Here, you can also use other preload const preload = join(__dirname, '../preload/index.js') -// 🚧 Use ['ENV_NAME'] avoid vite:define plugin -const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}` +const url = process.env.VITE_DEV_SERVER_URL const indexHtml = join(ROOT_PATH.dist, 'index.html') async function createWindow() { diff --git a/package.json b/package.json index ba15f97..bd8ea1e 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,12 @@ "vue": "^3.2.37", "vue-tsc": "^0.40.1" }, - "env": { - "VITE_DEV_SERVER_HOST": "127.0.0.1", - "VITE_DEV_SERVER_PORT": 3344 + "debug": { + "env": { + "VITE_DEV_SERVER_HOST": "127.0.0.1", + "VITE_DEV_SERVER_PORT": 3344, + "VITE_DEV_SERVER_URL": "http://127.0.0.1:3344" + } }, "keywords": [ "electron", diff --git a/vite.config.ts b/vite.config.ts index 243abee..146861b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -42,8 +42,8 @@ export default defineConfig({ renderer: {}, }), ], - server: { - host: pkg.env.VITE_DEV_SERVER_HOST, - port: pkg.env.VITE_DEV_SERVER_PORT, - }, + server: process.env.VSCODE_DEBUG ? { + host: pkg.debug.env.VITE_DEV_SERVER_HOST, + port: pkg.debug.env.VITE_DEV_SERVER_PORT, + } : undefined, })