【问题标题】:Electron + React + Typescript + Visual Studio Code? Debug? Can I debug an electron-react app in visual studio?Electron + React + Typescript + Visual Studio 代码?调试?我可以在 Visual Studio 中调试电子反应应用程序吗?
【发布时间】:2018-12-10 01:41:55
【问题描述】:

使用一些样板代码,我可以让我的电子应用程序在 Visual Studio 代码中工作。我可以为 main.js 打断点,但不能为我的任何 typescript/React 代码打断点。我正在使用 webpack 进行构建,但没有与之结婚。我如何为 React 的东西连接调试器?

我从这些演练开始:medium.comtypescriptlang.org

这是我的配置文件

launch.js

{
// 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",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "preLaunchTask": "webpack",
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
        "program": "${workspaceFolder}/main.js",
        "runtimeArgs": [
            ".",
            "--enable-logging"
        ]
    }
]
}

tasks.js

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "webpack",
        "command": "webpack",
        "args": []
    }
]
}

tsconfig.json

{
"compilerOptions": {
    "outDir": "./",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "target": "es5",
    "jsx": "react"
},
"include": [
    "./src/**/*"
]
}

webpack.config.js

module.exports = {
    entry: "./src/index.tsx",
    output: {
        filename: "./bundle.js",
        //path: __dirname + "/dist"        
    },
    mode: "production" ,

// Enable sourcemaps for debugging webpack's output.
    devtool: "source-map",

    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".json"]
    },

    module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },

            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },

// When importing a module whose path matches one of the following, just
    // assume a corresponding global variable exists and use that instead.
    // This is important because it allows us to avoid bundling all of our
    // dependencies, which allows browsers to cache those libraries between builds.
    externals: {
        // "react": "React",
        // "react-dom": "ReactDOM"
    },
};

【问题讨论】:

    标签: reactjs typescript webpack electron


    【解决方案1】:

    我解决了!找到答案from Microsoft。安装Debugger for Chrome;将 tasks.json 更改为以下内容,然后启动一个项目,然后启动另一个项目。 它可以与 Typescript、Webpack 和 React 完美搭配!

    {
    // 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",
    "configurations": [  
        {
            "type": "node",
            "request": "launch",
            "name": "Electron: Main",
            "preLaunchTask": "webpack",
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
            "program": "${workspaceFolder}/main.js",
            "runtimeArgs": [
                ".",
                "--enable-logging",
                "--remote-debugging-port=9223",
            ]
        },
          {
              "name": "Electron: Renderer",
              "type": "chrome",
              "request": "attach",
              "port": 9223,
              "webRoot": "${workspaceFolder}",
              "timeout": 30000
          }
    ],
    "compounds": [
          {
              "name": "Electron: All",
              "configurations": [
                  "Electron: Main",
                  "Electron: Renderer"
              ]
          }
      ]
    }
    

    【讨论】:

    • 添加到您的答案中,我遇到了类似的问题。我想实现调试三个实例(主要和两个入口点)的能力。为此,我创建了一个样板文件,可能会派上用场github.com/ShaharHD/…
    猜你喜欢
    • 2016-10-28
    • 2022-06-15
    • 2018-06-20
    • 2012-09-24
    • 1970-01-01
    • 2016-06-19
    • 2013-01-04
    • 2018-07-27
    相关资源
    最近更新 更多