-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: remove unused assets css in dist #20778
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
base: main
Are you sure you want to change the base?
feat: remove unused assets css in dist #20778
Conversation
@luffy84217 The tests are needed for both bugs and features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are failing.
Also the code doesn't look right. This would remove all assets that are not used from chunks and css files. But the asset might be emitted by a plugin that Vite itself is not aware of and Vite shouldn't remove those assets.
I guess we can use needsCodeReference
if we can mark the asset as used. I'm not sure if we can mark the asset as used though.
@sapphi-red Got it! I will check test and make it pass. |
When one imports an asset (let's say .svg) using import.meta.glob(..., { eager: true, import: 'default' }) new path will be inlined in a const and then this const get's tree-shaked/optimized, corresponding asset is not excluded from the final build. It's expected that no unused assets, especially heavy ones like fonts and images, are not included in final build. Fix: vitejs#19949 Ref: https://github.com/BerkliumBirb/vite-broken-tree-shaking
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1cc7b9e
to
ad6e714
Compare
@sapphi-red I used needsCodeReference to emit file and get reference Id, but it doesn't mark the asset as used as we thought. It doesn't behave like what official says |
Vite doesn't use |
Description
When one imports an asset (let's say .svg) using import.meta.glob(..., { eager: true, import: 'default' }) new path will be inlined in a const and then this const get's tree-shaked/optimized, corresponding asset is not excluded from the final build.
It's expected that no unused assets, especially heavy ones like fonts and images, are not included in final build.
Fix: #19949
Ref: https://github.com/BerkliumBirb/vite-broken-tree-shaking