-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vite 5.1.3 will lost js & css in html if build.rollupOptions.input
is relative path
#15992
Comments
I am experiencing the same thing but I don't think the problem is multi builds per se. The issue happens when you add the rollupOptions even on single entry builds:
When I built with:
It still failed to include the JS and CSS. Edit: I tried with Vite 4.5.2 and everything worked as expected. There must be an issue with Vite 5 and Rollup. |
This seems to only happen on Windows. A workaround is to call import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
build: {
rollupOptions: {
input: {
index: path.resolve('index.html'),
test: path.resolve('test.html')
}
}
}
}) |
related: #15153 |
I am also experiencing the same phenomenon. When built, the files exist in dist but are not referenced in html. On the other hand, if you use Vite version 4.5.2, you can see that the reference is inserted normally.
|
The workaround becomes an issue if one is using glob to get the paths. For multipage applications, you're going to have to resolve multiple files which could become unmaintainable depending on the number. EDIT: This should work for now...
|
build.rollupOptions.input
is relative path
I just bumped into this, it's really painful bug - it didn't trigger on CI (which is Linux), so I noticed it a long time after it was introduced in the codebase and took me few hours to figure out. Is this a bug in Rollup or Vite? If can't be easily fixed, I'd at least add note to docs (Vite or Rollup?), because it's easy to bump into it accidentaly. |
I got faced with this bug since Vite 5.1, too. It's not present in 5.0.12, but still exists in 5.2.8. I've traced it down to a bug in Vite which is related to path handling and manifests itself only under Windows filesystems. I've traced it down to vite/packages/vite/src/node/plugins/html.ts Line 816 in 102c2fd
chunk.facadeModuleId is something like C:\Users\rse\xxx\index.html (the Windows path separation characters are in place) and the id is C:/Users/rse/xxx/index.html (where POSIX path separation characters are in place). As a result, the chunk is not found and hence the tags not emitted during the HTML generation. The workaround by using path.resolve() on the build.rollupOptions.input works, but it would be better if the comparison inside Vite is fixed. I propose to change chunk.facadeModuleId === id with chunk.facadeModuleId === normalizePath(id) to fix this nasty bug. For a little bit better performance, use const normalizedId = normalizePath(id) at the start of the loop and then twice us normalizeId in the loop (there is already a call to normalizePath(id) there).
|
…aration characters exists than on POSIX filesystems (this fixes vitejs#15992)
Closing as #16421 is merged. |
Describe the bug
vite 5.1.3 will lost js & css in html after build multiple html input
it works in vite4
Reproduction
https://github.com/wxpwxpwxp/multi_page_vite_demo/tree/master
Steps to reproduce
cd vite5
pnpm i
pnpm run build
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: