-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Images not showing up in output folder #452
Comments
Hi. The What you have done now is definitely bundle it into the javascript by using file-loader, always making a base64. The way you should handle this in electron-webpack is using the "static assets" feature: https://webpack.electron.build/using-static-assets import path from "path";
import * as url from "url";
const isDevelopment = process.env.NODE_ENV !== "production";
// see https://github.com/electron-userland/electron-webpack/issues/241#issuecomment-582920906
export default function getStatic(relativePathToAsset = "") {
if (isDevelopment) {
return url.resolve(window.location.origin, relativePathToAsset);
}
return path.resolve(__static, relativePathToAsset);
}
// e.g. react <audio src={ getStatic('sounds/sound.mp3') } />
// e.g. js document.write(`<img class="logo" src="${getStatic("electron.png")}" />`); What it does is: In development, it returns a URL (with http: etc) pointing to the file as hosted by webpack-dev-server, and at production, it returns a local file: path to file inside aforementioned asar file, at the installed location of your app. Sounds complicated, but I totally recommend doing it that way, and reverting your changes up there. You should check out this example project i set up once: https://github.com/loopmode/electron-webpack-static-examples |
I've spent a more than a day debugging why my images and sound files were accessible in development but did not appear in the dist folder. Finally I have a "Fix" which is working for me, but I don't understand why is was necessary. Bellow is what I put into my webpack.renderer.js file.
Can anyone explain why the "url-loader" was being used for sound and image files? I'm not experienced in any of this, but because I had this issue is seems to me that this is a bug in electron webpack?
The text was updated successfully, but these errors were encountered: