Closed austins closed 1 year ago
I had a look at #21. For vite.config.ts, the base
(which can only be absolute, ./
or empty string) seems to only affect Vite's asset paths for things like font urls in css files, but not keys in the manifest. Vite outputs the key based on root
which is then relative to where the manifest.json is.
Tried setting the Base in appsettings.json to assets
(no slashes). Possibly a bug - the key slashes are not normalized.
Base assets/
will work with the tag helpers prefixed with ~/assets/
. This whole issue goes away now when dev server isn't running. But with the tag helper set to that path, the dev server can't find the file since it's actually at /
.
Hello.
If you want to use a custom directory, then set the Base option in your app settings and also in your vite.config.ts
file like this:
https://github.com/Eptagone/Vite.AspNetCore/issues/21#issuecomment-1586316537
If this doesn't work, please share a reproduction repo.
It works. Base option to /assets/
, Vite base to /assets/
and link in tag helpers must be prepended with ~/assets/
.
Thank you!
Vite.AspNetCore v1.8.0
This could just be a configuration issue, but if not, it seems like the Base setting used for manifest base path shouldn't be combined with the key of the chunk in ViteManifest or the base isn't used when accessing the key from the manifest in the tag helper.
Issue Details
appsettings.json:
_Layout.cshtml:
vite.config.ts:
This config allows Vite build to
./wwwroot/assets
like pictured below:With this config, the resulting manifest.json is:
The keys in the manifest will also differ if you have a different
root
like so:In this case, Vite generates keys with the folder name like
Assets/app.ts
.But to the first example above, in that case, the root is
./Assets
, the key would be generated likeapp.ts
. The ViteManifest class combines themstring key = Path.Combine(this._base, chunk.Key);
so the tag helper would look for key in manifest that will return null.Since I have
emptyOutDir: true
, I should want to avoid setting outDir to./wwwroot
as there may be other content such as favicon, file uploads, other static assets like images used in the views, etc.Proposals
Some ideas:
vite.config.ts
).