mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 11:56:36 +08:00
refactor: better debug experience
This commit is contained in:
parent
e06b90e612
commit
c7b3e4a151
14
.vscode/.debug.script.mjs
vendored
Normal file
14
.vscode/.debug.script.mjs
vendored
Normal 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')
|
95
.vscode/launch.json
vendored
95
.vscode/launch.json
vendored
@ -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"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
23
.vscode/tasks.json
vendored
23
.vscode/tasks.json
vendored
@ -1,21 +1,14 @@
|
|||||||
{
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "npm",
|
"label": "start .debug.script.mjs",
|
||||||
"script": "prebuild",
|
"type": "shell",
|
||||||
"group": "build",
|
"command": "node .vscode/.debug.script.mjs",
|
||||||
"problemMatcher": [],
|
"isBackground": true,
|
||||||
"label": "npm: prebuild",
|
"problemMatcher": []
|
||||||
"detail": "vue-tsc --project packages/renderer/tsconfig.json --noEmit && node scripts/build.mjs"
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "npm",
|
|
||||||
"script": "debug",
|
|
||||||
"problemMatcher": [],
|
|
||||||
"label": "npm: debug",
|
|
||||||
"detail": "npm run prebuild && vite ./packages/renderer",
|
|
||||||
"group": "build"
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user