Skip to content

[docs] sample project should demonstrate how to force images to be bundled with appΒ #3560

@nycki93

Description

@nycki93

Two years ago, a user asked this and got no answers. Their problem was easy to understand -- "hey, when I add an image to /src/assets, it appears in the dev server, but not in the compiled app. What gives?"

I went down several rabbit holes trying to solve the same problem in my own app. The sample app clearly shows that you can put files in /src/assets such as "tauri.svg" and they appear in the compiled android apk just fine, but when I added my own image and set it to appear when a button is pressed, it showed a broken image tile instead. What the hell? Are svgs "magic" somehow? Is there a secret config file that doesn't show up when I search for "svg" in the source code? What am I missing?

It turns out that the problem is that Tauri uses Vite for bundling, and Vite is smart and doesn't bundle any assets that don't appear in index.html. So my appearing png is getting excluded from the bundle, as Vite isn't clever enough to notice that I summon it later from JavaScript. My workaround was to include all my images in index.html and just have them be hidden until needed, but there's a more elegant solution: add the assets folder explicitly in the Vite bundler! After all, it's not like the user will ever put something in /src/assets that they don't want to be in their app, right? I think the sample project should demonstrate this, to save a ton of head banging later.

https://vite.dev/guide/build#multi-page-app

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    πŸͺ΅ Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions