-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Assets with the same content are de-duplicated at build time #8632
Comments
I found this is not rollup's behavior. vite/packages/vite/src/node/plugins/asset.ts Line 325 in 2b7e836
has cached the assests by hashcontent. How can I disable this behavior? Looking forward to your answer |
I also think that this isn't the best here. Maybe we should hash the input file name instead. It is an interesting optimization but feels to me that people should opt into it. |
Isn't it a good thing that same content assets are deduped to reduce bundle size? |
Of course it is very good for reducing the bundle size in SPA.
This made me hard to deploy |
The possible issues I see are:
There is also a perf implication of computing this hash. Maybe it is worthy, but it was surprising to me so at least we should better document it. |
Thanks for the explanations. Yeah I think this makes sense to me too. It's rare for someone to have to completely equal assets, and if they did it's likely intended and we should separate them. Regarding perf, that's a good point too. It seems like it's being used for various stuff though so it might not be easy to optimize it. |
Is there a reason this is closed? I think the issue is valid. |
Sorry, my bad. |
today we also got this issue. I've checked hash in CLI - the same content, but different names
and there are not both files in the manifest.json. May be it is possible to calculating hashes depending not only by content, but on filename, modification date or smt else ? Is there some temp solution for this issue ? |
Hey folks, I've hit this with the Laravel integration as well, and I've proposed the following fix: #9928 It is my opinion that if two files are the same e.g.
That is a suitable solution to include the file in the build once, but populate the manifest with two entries. {
"loader.svg": {
"file": "assets/loader.01234.svg",
"src": "loader.svg"
},
"spinner.svg": {
"file": "assets/loader.01234.svg",
"spinner.svg"
}
// ...
} This means that if you are compressing images it only has to compress the one image, rather than duplicate images and also that your bundle size is small i.e. one image rather than two are ouput. @dostrog it is my personal opinion that although your issue is related, it is a unique issue. I wonder if Vite could offer a "hash" config option that gets the file etc. and that way for the 95% use case you don't need anything, but for the 5% when clashes occur there is an escape hatch. export default defineConfig({
hasher: (file) => md5(file.contents) + md5(file.fileName),
// ...
}; I'm no JS expert though, so this might be a silly idea. |
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:
|
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! |
I've just checked with this PR successfully resolves our issue with the same content in different files also. Thank you guys! |
Closing as it seems #9928 was enough. |
@sapphi-red sorry for the late reply. i've checked the reproduction and update vite to lastest, and found this is not solved. Here is the repro: https://stackblitz.com/edit/vitejs-output-file-paths-ylbeyd |
@hemengke1997 #8632 (comment) |
@sapphi-red What I hope is that the duplicated assets will not be deduplicated after bundle, and the problem solved by this pr #9928 is the manifest reference. |
@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 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 |
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
vite/packages/vite/src/node/plugins/asset.ts
Line 325 in 2b7e836
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
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: