electron-vite-react icon indicating copy to clipboard operation
electron-vite-react copied to clipboard

Request: Dev mode to also use file:// protocol

Open Kilian opened this issue 3 years ago • 5 comments

In electron-vite-react the developer mode serves index.html from a web server on localhost, but the build serves that file using the file:// protocol. Can this be changed such that development mode also uses a file?

The reason I'm requesting this is that http: and file: have a different permission structure in browsers, so things that work fine in development mode could break in production, and this is a breeding ground for bugs.

For example, cookies work on localhost but not on the file: protocol. Conversely, loading images from disk (with the file: protocol) and showing them works if you load them from a page served over the file: protocol but are prevented from being shown due to cross-origin security on localhost.

Making sure the development and production environments of your app are served over the same protocol means there is a smaller chance for bugs related to that difference.

Kilian avatar Aug 22 '22 07:08 Kilian

The easiest way, you can put the built Renderer files on a remove serve. If you don't wath that, you need to start a server locally.

caoxiemeihao avatar Aug 22 '22 10:08 caoxiemeihao

I want it the other way around: Both development and production using the file protocol instead of a web server. This would be a good improvement to the boilerplate.

Kilian avatar Aug 22 '22 15:08 Kilian

Seems like a good idea, but would lose some great features like HRM.

caoxiemeihao avatar Aug 23 '22 00:08 caoxiemeihao

You could serve the HTML as a file but HMR the JS? (Not sure if that's possible with Vite because the html is the entry-point, but it's the architecture I currently use with webpack)

Kilian avatar Aug 23 '22 08:08 Kilian

To provide for the use of Electron-Renderer HTML static after buildding, will lose Vite brings many bendfits. May do more harm than good, or it's not suitable for use Vite.

caoxiemeihao avatar Aug 24 '22 00:08 caoxiemeihao