与Webpack捆绑在一起的Node或Electron Main Process的VSCode调试

时间:2017-01-31 18:53:54

标签: debugging typescript webpack visual-studio-code electron

My Electron主进程是使用TypeScript编写的,并捆绑了Webpack 2。

通过ts-loaderbabel-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'
  }
}

2 个答案:

答案 0 :(得分:5)

VSCode配置

重要的是给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配置

在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。希望有所帮助。