首页 > 解决方案 > 使用 React Typescript CRA 设置 Electron

问题描述

_____ 项目描述 _____

我将我的 Typescript & React 项目作为一个 Web 应用程序开始,我目前正在将其完全转换为一个 Electron 应用程序。不过,我在这方面遇到了一些麻烦。

_____ 我目前在哪里 _____

我按照本教程让 Electron 工作。它工作正常,除了electron.js文件(在名为 的教程中main.js,我将它放在我src的文件夹中,而不是public文件夹中)是一个 javascript 文件。这不会妨碍我的应用程序运行,但我更喜欢使用 Typescript 格式。这就是我所坚持的。我将它转换为 Typescript 文件,但我无法从我的package.json配置中指向它。

_____ 问题描述 _____

据我了解,mainin 中的属性package.json需要指向这个electron.ts文件。但当然,该文件没有得到正确处理,因为它不是 javascript 文件。

_____ 问题 _____

我怎样才能以某种方式指向electron.ts文件?在运行时生成的转译代码在哪里?也许我可以将main房产指向那里?

_____ package.json _____

  ...,
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom",
    "electron-dev": "concurrently \"BROWSER=none npm run start\" \"wait-on http://localhost:3000 && electron .\"",
    "electron-pack": "build -- em.main=build/electron.js",
    "preelectron-pack": "npm run build"
  },
  "main": "src/electron.ts",
  "homepage": "./",
  "build": {
    "appId": "com.example.electron-cra",
    "files": [
      "build/**/*",
      "node_modules/**/*"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },
  ...

标签: javascriptreactjstypescriptelectron

解决方案


The fastest route that I found to getting typescript up and running was with electron-webpack.

With the add-ons, it's got your requirements covered. I've used this to great success for an electron-react-redux application.


推荐阅读