Closed lubomirblazekcz closed 3 years ago
Another problem is that when transformIndexHtml
is used it only works for public/example.html but not for example.html
I think this is expected. See https://github.com/vitejs/vite/issues/2132#issuecomment-783468908
See comment linked by @CHOYSEN, closing as this is expected.
Sorry but this seems to me as an jssue. If it's working for /public/file.css I would expect this to work also for /file.css
I am using public dir as a workaround for middlewaring files urls from /directory/ to / because I didn't find any other option to do this
Could you explain more about the use case you are trying to workaround?
I am using vite as dev server to serve asset files from /public/ directory (or similiar type of directory, /www/ etc.) and source files from /src/
So the structure can look this way: (this is my structure where I don't use build in vite)
This is typical vanilla static site project structure. Currently this is only possible if you have your files in root, rather then in www (or diffrent directory). Or if you use public dir, which has it's problems as I said.
I described similiar problem in here https://github.com/vitejs/vite/issues/3354 where I find out that it's possible to create middleware, but that only works for .html files not other assets and build doesn't exactly work with this.
With using build with vite I would expect the final structure (after build) look something like this. Which would be typical php framework structure. Which I want to replicate, because of using Vite for creating templates for PHP applications.
eg. this is how I am currently using vite with such a structure https://github.com/newlogic-digital/core-starter I'm using vite as a dev server (with the javascript API), but build is handled with gulp
@patak-js disregard my last comments, I was doing this wrong (https://github.com/vitejs/vite/issues/3354#issuecomment-842331283)
I still need to use public dir for my purposes though, because I want to serve *.html files from public and HMR only works on full path /public/file.html not /file.html - that was my primary problem with this issue.
And this seems to be problem with middleware in generaly, once you transform the path from original to different url, HMR works only for the original url.
see example here - https://github.com/evromalarkey/vite-test-middleware
So HMR works for /public/file.ext but not for /file.ext or anyother transformed urls with middleware. Same if you create custom middleware for eg. transforming path eg. from /index.html to /templates/index.html
Ok I am propably a comment spammer today, sorry about that, I managed to workaround this as well.
So if anyone wants to workaround this as me, you can watch for changes with plugin api. You can handle reload in public directory with this aswell.
{
name: 'reload',
handleHotUpdate({ file, server }) {
if (file.endsWith('.html')) {
server.ws.send({
type: 'full-reload',
path: '*'
});
}
},
}
Describe the bug
When you move index.html to public directory, or if you have any other file there, the changes are not reloaded in browser.
Reproduction
Create example.html file in public directory and run vite, then try to change anything in that file. Server will not refresh.
If you run the file on public/example.html, it works correctly but then you get this warning, which is correct.
Page reload should work in both cases - example.html and public/example.html
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Before submitting the issue, please make sure you do the following