electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.41k stars 506 forks source link

Electron is packaged into loadFile or loadURL. How to configure the vite proxy service? #3418

Closed xhc-code closed 7 months ago

xhc-code commented 10 months ago

Pre-flight checklist

Problem description

I use electron-forge, which is an html page built by vite loaded through loadFile and loadurl. It is built using vite, but I encountered a problem, which is vite+vue+axios. The proxy service configuration configured through vite is not used by electron. , but how should I configure the front-end axios to request the interface URL of the specified address? I don't want to hard-code this path. I want to use environment variables to load different api interface URLs according to different environments. How can I achieve this?

Proposed solution

none

Alternatives considered

none

Additional information

No response

caoxiemeihao commented 8 months ago

If you use axios in the Renderer process, you can config the Proxy in vite.renderer.config.mjs

import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig({
+ server: {
+   proxy: {},
+ },
});
xhc-code commented 1 month ago

If you use axios in the Renderer process, you can config the Proxy in vite.renderer.config.mjs

import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig({
+ server: {
+   proxy: {},
+ },
});

Thank you

xhc-code commented 1 month ago

This is not possible because Vite, after being built, is a static file and will not contain this configuration file. I expect it to be used in a production environment because using the file protocol has many limitations. The expectation is that after Electron starts, the proxy server starts, and Electron loads the content of this link through the loadURL