umbrella22 / electron-vite-template

This project is a vue3 + Vite + electron project template composed of Vite and rollup. It has the same functions as my previous electron+Vue+template project
Other
398 stars 107 forks source link

为什么你的主进程里导入模块可以使用`import {app} from 'electron';`,需要对主进程进行什么配置吗? #41

Closed helptome1 closed 2 years ago

helptome1 commented 2 years ago

为什么你的主进程里导入模块可以使用import {app} from 'electron';,需要对主进程进行什么配置吗?

umbrella22 commented 2 years ago

你这个问的我一时间就不知道该怎么回答了.....因为 我的主进程经过编译了啊,你没发现我的主进程还是ts吗?

dest1n1s commented 2 years ago

想请教一下为何在渲染进程中可以使用const { ipcRenderer } = require('electron')而不能使用import { ipcRenderer } from 'electron'?后者会报错path.join is not a function

我猜测可能是因为path包是 node 专有的,但我依然不太理解为何 require 不会引发这一问题。

umbrella22 commented 2 years ago

@dest1n1s 你猜测的没错,因为vite会接管import行为,对于vite而言,它没有处理原生依赖的能力,所以需要使用require去规避

dest1n1s commented 2 years ago

明白了,感谢大佬解答!