forge icon indicating copy to clipboard operation
forge copied to clipboard

electron-forge + vite + vue package exe, cannot access resources?

Open xhc-code opened this issue 2 years ago • 3 comments

Pre-flight checklist

  • [X] I have read the contribution documentation for this project.
  • [X] I agree to follow the code of conduct that this project uses.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.1

Electron version

27.1

Operating system

win10

Last known working Electron Forge version

No response

Expected behavior

Open the exe and you can access the project resources of vue normally.

Actual behavior

Hello, according to the electron-vite template file, asar is turned on, and all static pages are put into the asar file. However, after the electron application is packaged into exe through electron-forge, the vue-related resource files and homepage index.html cannot be accessed. , all electron configurations are based on vite template files.

Directory Structure: root root/electron stores electron's main.js and preload.js files here. Root/src/ is where the Vue-related vue and main.js (vue entry files) files are stored.

Electron's main.js file is about how the window object is loaded.

     if (app.isPackaged) {
         mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
         mainWindow.webContents.openDevTools()
     } else {
         mainWindow.loadURL('http://localhost:8000/')
         mainWindow.webContents.openDevTools()
     }

Open the exe and check that the console is accessed in the form of E:/assets/xxx.js. The access resource does not exist. This path is definitely wrong, but everything that can be configured is configured. What is causing this problem? How should I solve this problem of not being able to access resource files?

Steps to reproduce

exec npm run make command

Additional information

No response

xhc-code avatar Nov 18 '23 09:11 xhc-code

The error path file:///D:/assets/index-09787f94.js

xhc-code avatar Nov 18 '23 09:11 xhc-code

Can you provide a minimal reproduction repo?

caoxiemeihao avatar Jan 12 '24 01:01 caoxiemeihao

Same issue. Did you figure out a solution?

akanksha-atrey avatar Mar 08 '24 17:03 akanksha-atrey