My Electron主进程是使用TypeScript编写的,并捆绑了Webpack 2。
通过ts-loader
和babel-loader
进行转诊。
开发模式使用main process configuration启动webpack --watch
。
我无法使用VSCode调试器调试主进程。
在入口点src/main/index.ts
中添加断点没有任何效果。
.vscode/launch.js
{
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeArgs": [
"${workspaceRoot}",
"--remote-debugging-port=9222"
],
"sourceMaps": true
}
]
}
webpack.development.js
{
target: 'electron',
devtool: 'source-map',
entry: {
main: join(__dirname, 'src/main/index')
},
output: {
path: join(__dirname, 'app'),
filename: '[name].js'
}
}
答案 0 :(得分:5)
重要的是给VSCode提供源文件,这是程序的入口点,并在"program"
键中指定它。
您还需要在"outFiles"
中指定Webpack生成的包。
{
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
// This is the important stuff
"program": "${workspaceRoot}/src/main/index.ts"
"outFiles": [
"${workspaceRoot}/app/main.js"
],
"sourceMaps": true
}
]
}
在Webpack配置中,您需要指定要在源图中编写模块源文件的完整路径。
{
output: {
devtoolModuleFilenameTemplate: '[absolute-resource-path]'
}
}
另外要注意选择未评估的源图,以允许VSCode静态查找相应的入口点。
我使用最小配置和更多解释创建了a repo。
答案 1 :(得分:1)
我不知道它是否可能,但--remote-debugging-port=9222
适用于v8-inspector协议,但电子节点尚不支持https://github.com/electron/electron/issues/6634 })。
由于这是一个启动配置,VS Code会将--debug=5858
传递给运行时,因此您不需要在此处指定端口。也许尝试添加--nolazy
。希望有所帮助。