Sun*_*ier 8 reactjs electron vite
我正在尝试将使用构建的电子应用程序转换create-react-app为ViteJS. 到目前为止,我已经解决了很多问题,但我的一个依赖项出现了问题。
出于性能原因,我的项目使用了 golang 内置的内部库,并且该库是从电子应用程序的主进程中调用的。但是,运行时出现以下错误vite build。
[commonjs--resolver] Unexpected character '\xef\xbf\xbd' (Note that you need plugins to import files that are not JavaScript)\nRun Code Online (Sandbox Code Playgroud)\n以下行会发生这种情况
\nmodule.exports = require('./build/Release/goapi.node');\nRun Code Online (Sandbox Code Playgroud)\ngoapi.node是编译好的库。该库是使用 node-gyp 编译的,我 100% 确定编译是正确的,因为它正在使用使用 create-react-app 的当前设置。
有没有插件可以添加vite来支持导入本机模块?如果没有,我该如何解决这个问题?
我在将node-pty添加到基于 Electron Forge\'s Vite + TypeScript template的项目时遇到了类似的问题。
\n我的解决方案是在 Rollup 配置中将 node-pty 标记为外部,这告诉 Rollup 将该模块保留在包的外部。
\n在我的“vite.main.config.ts”文件(专门用于编译 Electron 主进程)中,我在“defineConfig”中添加了一个“build”部分来定义此 Rollup 选项:
\nexport default defineConfig({\n build: {\n rollupOptions: {\n external: ["node-pty"]\n }\n },\n \xe2\x80\xa6\n});\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
613 次 |
| 最近记录: |