refactor: better debug experience

This commit is contained in:
草鞋没号 2022-03-15 08:35:11 +08:00
parent e06b90e612
commit c7b3e4a151
4 changed files with 63 additions and 84 deletions

14
.vscode/.debug.script.mjs vendored Normal file
View File

@ -0,0 +1,14 @@
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { createRequire } from 'module'
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}`)
fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n'))
// bootstrap
import('../scripts/watch.mjs?debug=vscode')

97
.vscode/launch.json vendored
View File

@ -1,71 +1,44 @@
{ {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Main(inspector)",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9222",
"${workspaceFolder}/dist/main/index.cjs",
],
"env": {
"DEBUG": "true",
},
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"sourceMaps": true
},
{
"type": "chrome",
"request": "launch",
"name": "Renderer(inspector)",
"url": "http://localhost:9222",
"webRoot": "${workspaceFolder}/dist/packages/renderer",
},
{
"type": "node",
"request": "launch",
"name": "Main(vite)",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"${workspaceFolder}/dist/main/index.cjs",
],
"env": {
"VITE_DEV_SERVER_HOST": "127.0.0.1",
"VITE_DEV_SERVER_PORT": "3344",
},
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"sourceMaps": true
},
{
"type": "chrome",
"request": "launch",
"name": "Renderer(vite)",
"url": "http://localhost:3344",
"webRoot": "${workspaceFolder}/packages/renderer",
},
],
"compounds": [ "compounds": [
{ {
"name": "All(inspector)", "name": "Debug App",
"preLaunchTask": "start .debug.script.mjs",
"configurations": [ "configurations": [
"Renderer(inspector)", "Debug Main Process",
"Main(inspector)", "Debug Renderer Process"
], ],
"preLaunchTask": "npm: prebuild" "presentation": {
"hidden": false,
"group": "",
"order": 1
},
"stopAll": true
}
],
"configurations": [
{
"name": "Debug Main Process",
"type": "pwa-node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"runtimeArgs": [
"--remote-debugging-port=9229",
"${workspaceRoot}/dist/main/index.cjs"
],
"envFile": "${workspaceFolder}/.vscode/.debug.env"
}, },
{ {
"name": "All(vite serve)", "name": "Debug Renderer Process",
"configurations": [ "port": 9229,
"Renderer(vite)", "request": "attach",
"Main(vite)", "type": "pwa-chrome"
], },
"preLaunchTask": "npm: debug"
}
] ]
} }

33
.vscode/tasks.json vendored
View File

@ -1,21 +1,14 @@
{ {
"version": "2.0.0", // See https://go.microsoft.com/fwlink/?LinkId=733558
"tasks": [ // for the documentation about the tasks.json format
{ "version": "2.0.0",
"type": "npm", "tasks": [
"script": "prebuild", {
"group": "build", "label": "start .debug.script.mjs",
"problemMatcher": [], "type": "shell",
"label": "npm: prebuild", "command": "node .vscode/.debug.script.mjs",
"detail": "vue-tsc --project packages/renderer/tsconfig.json --noEmit && node scripts/build.mjs" "isBackground": true,
}, "problemMatcher": []
{ }
"type": "npm", ]
"script": "debug", }
"problemMatcher": [],
"label": "npm: debug",
"detail": "npm run prebuild && vite ./packages/renderer",
"group": "build"
},
]
}

View File

@ -26,8 +26,7 @@ async function createWindow() {
}, },
}) })
if (app.isPackaged || process.env['DEBUG']) { if (app.isPackaged) {
// Load built files in the debug mode instead of reading from vite server
win.loadFile(join(__dirname, '../renderer/index.html')) win.loadFile(join(__dirname, '../renderer/index.html'))
} else { } else {
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin // 🚧 Use ['ENV_NAME'] avoid vite:define plugin