首页 文章

在Visual Studio代码中调试Typescript应用程序时清空Electron窗口

提问于
浏览
1

我试图在Visual Studio Code(vs code)中使用Electron调试一个打字稿应用程序 - 一个终端模拟器Black-Screen .

我试图通过从vs代码启动我的应用程序来做到这一点 . 我在主要的Typescript应用程序文件src/main/Main.ts中设置的断点按预期打破了,我可以检查变量值 .

Electron也在推出,但Black-Screen应用程序不会加载Electron(我只看到一个emtpy Electron窗口) . 查看空电子窗口的屏幕截图 .

enter image description here

我可以使用typescript-compiler(tsc)来转换应用程序,并且不会生成错误,并且可以在我期望的文件夹中看到已编译的javascript(src / bin /) . 我也可以使用npm(“npm start”)成功启动应用程序 .

以下是相关的项目配置文件:

  • src / tsconfig.json
{
    "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "noEmitOnError": true,
    "pretty": true,
    "jsx": "react",
    "sourceMap": true,
    "outDir": "bin"
  }
}
  • .vscode / tasks.json文件注意 . 在终端“tsc --project src”中执行等效命令会生成没有错误或警告的已转换的js代码 .
{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["--project", "src"],
    "problemMatcher": "$tsc"
}
  • .vscode / launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Black-Screen",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/src/main/Main.ts",
      "stopOnEntry": false,
      "cwd": "${workspaceRoot}",
      "sourceMaps": true,
      "externalConsole": false,
      "outDir": "${workspaceRoot}/src/bin",
      "runtimeExecutable": "${workspaceRoot}/node_modules/electron-prebuilt/dist/electron",
      // Optional arguments passed to the runtime executable.
      "runtimeArgs": ["--nolazy"],
      // Environment variables passed to the program.
      "env": {
         "NODE_ENV": "development"
      }
    }
  ]
}

注意 . launch.json配置在调试控制台中生成命令行语句: /home/michael/development/black-screen/node_modules/electron-prebuilt/dist/electron --debug-brk=3323 --nolazy src/bin/main/Main.js .

查看调试控制台的截图 .
enter image description here

希望有人遇到类似的问题与vs代码和电子,并可以协助:)

1 回答

  • 1

    首先,如果你使用它会更好

    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron"
    

    如果您在Windows或OS X上开发,那么您将遇到麻烦,因为您必须使用每个环境的可执行文件 .

    那就是说Electron要求你的app的 outDirresources/app 有关 . http://electron.atom.io/docs/tutorial/application-distribution/

相关问题