Closed samuelbirch closed 2 years ago
Is this something that isn't working correctly currently? Shouldn't anything in /public
be served by the dev server if you're running it?
If i have assets that are referenced in the css or js then it all works fine.
Its when i want to use a public asset, the dev server is working but not when its been built as the asset is not in the manifest.
This tweak doesn't use the manifest and return the path prefixed with the destination folder
Ah I see. They are solving this in Vite 3 via this PR: https://github.com/vitejs/vite/pull/6649#issuecomment-1159278169
Are you able to wait until then, or...?
Yes i could wait until then (although don't know when "then" is?)
I'm assuming that PR is about being able to add assets to the manifest (outside of js/css), but wouldn't we still have the same issue with public assets (that we don't want hashed) not being able to correctly reference?
Ah yes, you're right on both fronts. How about this for an idea -- since they have hard-coded public
what if instead of a flag, we looked for public
in the first segment of the incoming URL, and did it automagically?
"public" can be configured using the "publicDir" property, I have it set to "/src/assets"
instead of a flag, we could add another function: craft.vite.publicAsset('url'). I thought a flag might be cleaner.
Roger that. Will merge it in and update the docs -- I'm assuming this works with the devServer
as well as in production?
yes it works with both.
Thx for the PR!
adds a boolean as a second param to the
craft.vite.asset('url', true)
so that assets in the vite public folder can be referenced correctly.