alex.wei
alex.wei
建议,你使用esm语法,构建目标也是esm,也就无需这样处理。
> > * 这个和electron-vite无关,也和迁移无关,这是常识性问题,因为构建目标是cjs,这些cjs内置变量是无法被占用的和改写的,nodejs的内置变量怎么可能被改写呢,所以运行时错误信息就会抛出的。 > > * 无论你是esm编写还是cjs编写,electron-vite都会自己根据构建目标,做好兼容处理,所以你的这个处理是多余的,你用esm编写就按esm标准即可,当构建到cjs时,像import.meta.url, electron-vite就会去转换成支持cjs。这是现代构建工具的基本功能之一。 > > 可是我的构建目标是es 了解你的情况,构建目标为es时,electron-vite也会对___dirname这些做兼容处理,因为认为你使用了cjs语法,就会在头部插入和你实现同样的代码,就会有这个错误信息。既然是esm为何还要这样处理,同时require作为nodejs的关键字应该避免作为变量使用。
如果一定要这样处理,建议不要占用这些内置的变量,换个名字也不会有问题
你也可以直接使用__dirname, electron-vite 会自动处理
`base` option should not be set in production. More details: https://vitejs.dev/config/shared-options.html#base. In production, we use file protocol to load page.
@weiminghaoo 未能重现此问题,setInterval 是否有特殊逻辑,提供相关复现示例或更详尽的信息。
`electron-vite` already supports these. - https://evite.netlify.app - https://evite.netlify.app/guide/dev.html#multiple-windows-app
@andersk check out: https://electron-vite.org/guide/dev#limitations-of-sandboxing Because the require function is a polyfill with limited functionality, you will not be able to use CommonJS modules to separate your preload script into multiple...
@andersk I understand your idea now, maybe letting preload support a set of configurations just like rollup can avoid this problem. But it is restricted by Vite. But I think...
Is there any better suggestion?