vite: Assets with the same content are de-duplicated at build time
Describe the bug
Hi! I have many assets like svg and their [content] is the same. After vite build, I only got two svg. The rest have been merged together. I checked the code of vite in https://github.com/vitejs/vite/blob/2b7e836f84b56b5f3dc81e0f5f161a9b5f9154c0/packages/vite/src/node/plugins/asset.ts#L325. Is this made wrong? Or is this the default behavior of rollup. How can I get all assests after build? I don’t want chunk splitting.
Reproduction
https://stackblitz.com/edit/vitejs-output-file-paths-gftt9h?file=dist/manifest.json
System Info
vite 2.9.12
Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (16 by maintainers)
I am trying to cache packed results. Because my project structure is multi-page, and each page is not directly related, the speed will be slower every time it is fully bundled, so I need know whether the file needs to be removed from the cache by controlling the
hash. And multi-asset merging will cause cache instability. My need is very rare, so I don’t think there is any need to modify the vite source code. At first I thought it was a vite bundle bug. But I now think merging assets is reasonable for the vast majority of projects. Thank you for your enthusiasm and responsibility@hemengke1997 Yes I understand the difference. But we didn’t understand why you need to avoid the dedupe of the actual file. Would you provide more context about that?
I’ve just checked with
this PR successfully resolves our issue with the same content in different files also.
Thank you guys!
We decided today that there isn’t a good use case yet to justify an option to avoid deduplication. Would you check if @timacdonald’s PR is enough for your needs:
If not, please provide more context about the particular use case. Thanks!
Thanks for your reply! Yeah unique and rare, but exists.
at the moment I’ve just add file name + generate hash (unfortunately. do not have time for full PR) and use forked repo for Vite
in asset.ts:
Sorry, my bad. I thought this issue was unnecessary. I’m very sorry.