wails: Dynamic assets not loading in dev mode since updating vite to v5.0.0+
Description
since updating to vite 5.0.0+, dynamic assets are not served anymore when running wails dev, but the index.html file is instead. things are fine once compiled
To Reproduce
in a brand new project, follow the step in the dynamic assets example
whether fetching a non-exiting file or go.mod, the index.html file gets served
I have a repo with an example and troubleshooting steps: https://github.com/BenoitBotton/assethandler
Expected behaviour
expect files to get served or an error produced as in the example
Screenshots
No response
Attempted Fixes
No response
System Details
# Wails
Version | v2.7.1
# System
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS | Windows 10 Pro |
| Version | 2009 (Build: 22631) |
| ID | 23H2 |
| Go Version | go1.20.1 |
| Platform | windows |
| Architecture | amd64 |
| CPU | AMD Ryzen 9 5900HX with Radeon Graphics |
| GPU 1 | AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.) - Driver: 31.0.21023.2010 |
| GPU 2 | NVIDIA GeForce RTX 3070 Laptop GPU (NVIDIA) - Driver: 31.0.15.4633 |
| Memory | 64GB |
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status | Version |
| WebView2 | N/A | Installed | 121.0.2277.98 |
| Nodejs | N/A | Installed | 20.10.0 |
| npm | N/A | Installed | 9.8.1 |
| *upx | N/A | Available | |
| *nsis | N/A | Installed | v3.08 |
└─────────────── * - Optional Dependency ───────────────┘
# Diagnosis
Optional package(s) installation details:
- upx : Available at https://upx.github.io/
SUCCESS Your system is ready for Wails development!
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (17 by maintainers)
Commits related to this issue
- Add link to #3240 in note — committed to BenoitBotton/wails by BenoitBotton 3 years ago
One can do that with the
Middlewareif someone wants that. I personally would not introduce another preregistered path for this, because that can be achieved with just a custom middleware. We would just introduce another “magic” thing that is specific to wails.We can still drop
AssetHandlerif you want, but then people that want to usetemplmust add a middleware and drop thenexthandler. This assumes the middleware is behind all the internal wails middlewares, like the runtime, but we already discussed to lift the middleware up, so it is being called before any wails middlewares and people can add CORS handling.I’m open to whatever you want. I personally would not introduce some magic paths like
/wails/assethandler/for assethandler, because IMHO that’s the use case for a middleware and people are used to this from web frameworks. I think we should strive for a clean solution with clean rules and try to be more like web frameworks.My preferred solution would be probably like this: Let’s just drop the
fs.FScompletely from theapplication.AssetOptionsand leavehttp.Handlerandmiddleware. And middleware injects it at the beginning of all requests, even before Wails internal middlewares, so people can add CORS handling or add logging to Wails runtime requests and so on.Using an
fs.FSwould then look like this and if someone uses the external devserver, theapplication.AssetFileServerFSwould use the external server instead of using theassets.And if someone wants to have a custom path for images that get dynamically served, this would look like the following with e.g. chi:
Example with
http.ServeMuxin Go 1.22Just pushed the above proposal to
v3-alphabranch.hello i know that there is no solution until v3 comes out, but there is three ways to resolve this (this is for the new people who see the issue)
@BenoitBotton I guess the answer for this ticket is that unless you can find a way to make vite 5 work with its new behaviour and defaults, we recommend staying with Vite 4.
That’s when requesting the ‘/’ and indicates which file would have been loaded from the
assets fs.FS, so in this case the current directory, which is.. Because that is a directory, it will inernally load theindex.htmlfrom the fs.FS.