简体   繁体   English

如何在电子中使用打字稿而无需编译?

[英]How to use typescript in electron without having to compile?

So it looks like with newer electrons you can just start it off in typescript right away with所以看起来使用较新的电子,您可以立即在打字稿中启动它

electron main.ts电子干线

  1. Though you can't do electron ./main and you'd still need to require('./file.ts').虽然你不能做electron ./main并且你仍然需要 require('./file.ts')。
  2. And I noticed that when I build it the .exe still complains that it needs a main.js file.我注意到当我构建它时,.exe 仍然抱怨它需要一个 main.js 文件。

How can I solve these two issues without going with a compiler (just load typescript directly)?如何在不使用编译器的情况下解决这两个问题(只需直接加载打字稿)?

Electron is not supposed to execute TypeScript code directly so you have to convert it to Javascript before to be able to use it in electron. Electron 不应该直接执行 TypeScript 代码,因此您必须先将其转换为 Javascript,然后才能在 Electron 中使用它。 By the way here a useful link to refer: https://www.electronjs.org/blog/typescript顺便说一下,这里有一个有用的链接可供参考: https : //www.electronjs.org/blog/typescript

Please refer also to this question: How to add my own typescript classes in Electron project另请参阅此问题: How to add my own typescript classes in Electron project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM