【问题标题】:Sequential launch in VSCode debuggingVSCode 调试中的顺序启动
【发布时间】:2019-04-20 21:01:09
【问题描述】:

鉴于对 this question 的部分回答和解决,我现在有以下启动配置来调试我的 react-redux + electron 应用程序。

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Main",
      "program": "${workspaceFolder}/src/main.js",
      "protocol": "inspector",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "runtimeArgs": [
          "--remote-debugging-port=9229",
          "."
      ],
      "windows": {
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
      }
    },
    {
        "type": "node",
        "request": "launch",
        "name": "NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
          "run-script",
          "start"
        ],
        "port": 9229
    },
    {
        "type": "chrome",
        "request": "launch",
        "name": "Renderer",
        "url": "https://localhost:3000",
        "webRoot": "${workspaceFolder}/src",
        "runtimeExecutable": "C:/Users/[username]/AppData/Local/Programs/Opera developer/launcher.exe",
        "runtimeArgs": [
          "--remote-debugging-port=9229"
      ],
      "port": 9229
    }
  ],
  "compounds": [
    {
      "name": "All",
      "configurations": [
        "Main",
        "NPM",
        "Renderer"
      ]
    }
  ]
}

所以它是这样工作的:NPM 配置启动 node.js 服务器,然后RendererMain 分别调试前端部分和后端部分。

但是,当启动复合设置时,它们都会同时执行,https://localhost:3000/ 和选举应用程序都显示空白屏幕,直到服务器完全设置。

目前,一旦服务器启动就重新加载网页和电子客户端是可以的,但我只是好奇是否有办法制作顺序启动命令以使其更加优雅。有什么好主意吗?

【问题讨论】:

    标签: json reactjs debugging visual-studio-code electron


    【解决方案1】:

    我认为您可以通过附加而不是启动来使您的渲染器代码更加优雅。

    例如,我在启动主程序时使用了一个复合,然后使用以下内容附加到渲染器(无需重新加载)。

     {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch",
          "cwd": "${workspaceRoot}/src/app",
          "runtimeExecutable": "${workspaceRoot}/src/app/node_modules/.bin/electron",
          "windows": {
            "runtimeExecutable": "${workspaceRoot}/src/app/node_modules/.bin/electron.cmd"
          },
          "runtimeArgs": [
            "${workspaceRoot}/src/app",
            "--remote-debugging-port=9222"
          ],
          "console": "integratedTerminal",
          "sourceMaps": true,
          "outFiles": [
            "${workspaceRoot}/src/app/out/**/*.js",
          ],
          "protocol": "inspector",
        },
        {
          "type": "chrome",
          "request": "attach",
          "name": "Attach to Renderer",
          "trace": true,
          "webRoot": "${workspaceRoot}/src/app",
          "sourceMaps": true,
          "port": 9222,
          "timeout": 60000
        },
      ],
      "compounds": [
        {
          "name": "App Main & Renderer",
          "configurations": [
            "Launch App Main",
            "Attach to App Renderer"
          ]
        }
      ]
    }
    

    【讨论】:

    • 我猜一个简单的附加方法是行不通的。它给出了上一个问题中所述的相同问题(请参阅我的问题第一行的链接)。
    • 嗯,我没有这个问题。我在上面发布了我的完整配置。使用此配置,渲染器会自动附加,而无需 VS 代码下拉列表。它留下的唯一问题是您可能会错过渲染器中构造函数中的一些断点,具体取决于附加实际需要多长时间
    • 在启动 electron 和附加渲染器之前如何启动服务器?
    • 电子应用程序通常是桌面应用程序,所以我不设置服务器,我只是启动我的电子应用程序。在非调试模式下,我只会使用“电子”。开始我的申请。也许您有更复杂的设置。
    • 我明白了。我通过“电子化”现有的 React+Redux 应用程序创建了我的应用程序,因此它需要一个 node.js 服务器。
    猜你喜欢
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 2018-03-29
    • 2019-02-21
    • 2018-07-06
    • 2021-09-26
    • 2020-07-11
    • 2021-01-21
    相关资源
    最近更新 更多