使用 electron-forge 打包时如何预编译打字稿

How to precompile typescript when packaging with electron-forge

在应用程序真正加载之前,该应用程序会以空白屏幕启动一段时间

我正在使用 electron-forge 的 react-typescript template

我可以成功制作dmgdeb文件,但我注意到当我运行打包应用程序时,在应用程序实际运行之前会有一段时间的空白屏幕特别是第一次加载

我检查了分发文件,发现里面有完整的源代码,所以我猜是因为每次都要编译typescript

那么如何 "precompile" 我的源代码并使用它来制作可分发的应用程序?

更新: 由于该项目是其他同事开发的,所以我才发现这个项目正在使用electron-compile进行动态编译,也许解决方案与此有关?

I checked the distributable file and found the whole source code inside it, so I guess it's because it has to compile typescript every time?

这不是真的。当前稳定版使用 electron-prebuilt-compile (https://github.com/electron-userland/electron-forge/blob/1709af0bc53bd962466dd2025672b95f2e9399cc/packages/api/core/src/util/electron-version.ts#L6) 为打包时间的打字稿文件创建预编译缓存。实际文件系统中的模块解析仅需要 Typescript 源。

there will be a blank screen for a while before the app actually load especially the first time

这需要分析应用程序本身以了解同时发生的情况。模块解析可能需要很长时间,或者任何 js 执行时间被阻塞,但不分析它就无法判断。