Using assets with public folder #738
-
Hello all, I just started using vite-electron-builder and I'm having a blast, congrats to you ! :) I have a question though : the Vite documentation mentions in "Static Asset Handling" that I can include all sorts of assets that need in the public folder, at the root of the project (so, next to package.json), but I guess things are a bit different with Electron. How can I get (if possible from the renderer side) the absolute path to one file in particular ? Say, I have a file named "test.jpg", and I want to call a script on another application where I send the full path of the file. How can I do that (both in env and production modes, I don't mind having to if/else though) ? Tried __dirname, path.resolve("/test.jpg"), to no avail. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi. Honestly, I do not understand the essence of your problem.
Here by project, we mean "Vite project". In this template, each package is a separate "Vite project" and has its own root. Each package has a separate config and it is there that the path to the root of the "Vite project" is set. BTW |
Beta Was this translation helpful? Give feedback.
-
Ok, so moved the assets I was refering to to /packages/renderer/public (since I didn't want them bundled/processed/renamed by Vite), thanks for the tip, I'm still a bit new to this 😅 (transitioning from electron-webpack where there was only one project). My problem is, I would like to get the absolute path to the asset located in it. What I'm trying to do is call an external program and provide it with the full absolute path of the asset on the hard drive. Basically, I just wrote this, but I'm not sure it's done the "right" way : let thePath = path.join(appPath, 'packages/renderer/public/scripts/myscript.scr'); (in this example appPath points to app.getAppPath(), so the location where the app is run/installed, and the code will improve, it's just that way for out-of-context readability). It seems to work in dev mode, and through the app compiled with |
Beta Was this translation helpful? Give feedback.
Ok, so moved the assets I was refering to to /packages/renderer/public (since I didn't want them bundled/processed/renamed by Vite), thanks for the tip, I'm still a bit new to this 😅 (transitioning from electron-webpack where there was only one project).
My problem is, I would like to get the absolute path to the asset located in it. What I'm trying to do is call an external program and provide it with the full absolute path of the asset on the hard drive.
Basically, I just wrote this, but I'm not sure it's done the "right" way :
(in this example appPath points to app.getAppPath(), so the location where the…