javascript - 使用 React Typescript CRA 设置 Electron
问题描述
_____ 项目描述 _____
我将我的 Typescript & React 项目作为一个 Web 应用程序开始,我目前正在将其完全转换为一个 Electron 应用程序。不过,我在这方面遇到了一些麻烦。
_____ 我目前在哪里 _____
我按照本教程让 Electron 工作。它工作正常,除了electron.js
文件(在名为 的教程中main.js
,我将它放在我src
的文件夹中,而不是public
文件夹中)是一个 javascript 文件。这不会妨碍我的应用程序运行,但我更喜欢使用 Typescript 格式。这就是我所坚持的。我将它转换为 Typescript 文件,但我无法从我的package.json
配置中指向它。
_____ 问题描述 _____
据我了解,main
in 中的属性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"
}
},
...
解决方案
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.
推荐阅读
- python - 基本 Python 代码在新机器 (Mac) 上的工作方式不同
- javascript - 在不同的选项卡中多次使用整页
- c# - Fluent NHibernate:将空列表设置为 null
- html - 如何为嵌套的多 div 设置单独的样式?
- kubernetes - 为什么 kubectl cp 命令以退出代码 126 终止?
- javascript - 我需要使用 fetch 为数组中的每个图像添加图像元素到 DOM
- java - Google Cloud Platform Debugger for Compute Engine with Payara/Glassfish 应用服务器
- python - Django form.save(commit=False) 不添加 user_id
- python - 用于嵌套字典的 Python 表格
- typescript - 我可以将对象的现有属性“重新绑定”到打字稿中的另一种类型吗?