-
Notifications
You must be signed in to change notification settings - Fork 113
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
What is the correct path of "renderer/public"? #23
Comments
Interesting, looking at your build directory it should find the 404.png on What is being logged to the console? Are you getting a 404 from the network? Path looks fine to me, why do you think it's strange? |
I tried this on my Windows & Mac system to be sure, but can't seem to reproduce. |
I'm sorry for being busy and then forgot to reply.🥵 I've cloned a new project and try to reproduce the problem, and it seems ok. I need to find the difference between your project and mine. Thanks anyway😌 |
@Deluze hi, I got the same problem. I have a Everything works fine when in develop mode, but got an error when build to zip on Windows. The Any help would be greatly appreciated! |
Hey @dss886, what's your Vite config like? The default svg icons that come with this project work fine on my end. What commands are you running? |
@Deluze Hey,
const Path = require("path");
const vuePlugin = require("@vitejs/plugin-vue");
const { defineConfig } = require("vite");
/**
* https://vitejs.dev/config
*/
const config = defineConfig({
root: Path.join(__dirname, "src", "renderer"),
publicDir: "public",
server: {
port: 8080,
},
open: false,
build: {
outDir: Path.join(__dirname, "build", "renderer"),
emptyOutDir: true,
rollupOptions: {
input: {
main: Path.join(__dirname, "src", "renderer", "index.html"),
hardware: Path.join(__dirname, "src", "renderer", "plugins", "hardware", "index.html"),
spotlight: Path.join(__dirname, "src", "renderer", "plugins", "spotlight", "index.html"),
}
}
},
plugins: [vuePlugin()],
});
module.exports = config; Build Command: Build result is a zip file. After unzip is like: Unzip the app.asar file: |
@dss886 The directory tree in your last screenshot looks correct. Vite's behavior is to pull any file from the public dir into the build root (which is I tried to reproduce it on my Linux environment by packing up the build in a tar, deb and snap package but can't seem to reproduce. Could you create a minimal repo to reproduce this issue? @dss886 |
Hi @Deluze, I found the problem, but haven't solved it yet. I have a vue component named interface Props {
icon: string;
title: string;
subtitle?: string;
}
withDefaults(defineProps<Props>(), {
icon: "",
title: "",
subtitle: "",
}); App.vue pass the name of icon to the ListItem component: <ListItem
v-for="(item, index) in itemList"
:key="item.title"
:icon="item.icon"
:title="item.title"
/> But the <img
v-if="icon !== ''"
:src="'/' + icon"
class="icon"
> I tried removing string concat and passing the Do you have any suggestions? 😨 PS: You may want to check the minimal bug repo: |
Thanks @dss886 I'll take a look this weekend |
Hi all. Maybe this is unrelated, but I was hitting this exact problem with code that I was porting over. I'm using this template with Vuetify. I just cloned this template and added Vuetify, as described here. At that point if you just try a trivial change to App.vue you can experience this firsthand. I added a single Vuetify image:
So this code is in the same file, using the same image, as the code that works. The above will work with an Thanks to running into something similar in the past, I tried changing the file path from Maybe this will help someone else who happens upon this thread. |
To add some more information to this thread, it's difficult to use the There's a big difference when it comes to fetching resources from your dev server, compared to the final build. Dev Server Building your app <img src="/image.png"> into <img src="/absolute/path/to/image.png"> This is because there is of course no web server running on the host's machine. Instead, all resources need to be loaded directly from the filesystem. Runtime computed filepaths Imagine the following snippet: <script setup>
const filename = new Date().getDay() & 1 ? 'vite.svg' : 'vue.svg';
</script>
<template>
<img :src=`/${filename}`>
</template> Vite will not transform I'm not sure if there's a Vite option that will always inject the full path when there's a string starting with So... are there any other solutions? Yes! In case you have some icons that you want to show depending on the users device for example: import androidIconPath from './icons/android.svg';
import appleIconPath from './icons/apple.svg';
<script setup>
const iconPath = 2 > 5 ? androidIconPath : appleIconPath; // silly example
</script>
<template>
<img :src="iconPath"> <!-- This will work on both dev server and final build! -->
</template> I can believe this can become pretty cumbersome if you have 1000 icons. To conclude, I don't think this is an issue that has something to do with this template specifically. I don't really maintain this template any more as I'm not using Electron at all at the moment. |
Sorry for the late reply to this post. My solution at that time was indeed similar to the ones of @tob-at-lovelace , which using the relative paths. And I did the path-compute job like: const iconPath = computed(() => {
if (import.meta.env.DEV) {
return `/${props.icon}`;
} else {
// after packed, we are in renderer/plugins/xxx/
return `../../${props.icon}`;
}
}); But the solution of @Deluze is new knowledge to me and looks more elegant, I will learn and use it later! Thanks all, I'm really appreciate about it. @tob-at-lovelace @Deluze |
Closing this issue as the example used in the template now imports these files instead of using an absolute path (4c6c937) . Hopefully this will reduce confusion for everyone. |
so i'm adding an 404.png in renderer/public,
and using it like
src="/404.png"
it worked at develop mode, but failed to load at prod mode.
it seems like after build at prod mode, the resource path become strange
The text was updated successfully, but these errors were encountered: