Skip to content

Broken eagerly imported assets tree shaking #19949

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

Open
7 tasks done
BerkliumBirb opened this issue Apr 27, 2025 · 1 comment
Open
7 tasks done

Broken eagerly imported assets tree shaking #19949

BerkliumBirb opened this issue Apr 27, 2025 · 1 comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@BerkliumBirb
Copy link

Describe the bug

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.

Reproduction

https://github.com/BerkliumBirb/vite-broken-tree-shaking

Steps to reproduce

  1. clone repo
  2. npm i
  3. npm run build
  4. check out dist/

Expected to only have "dist/blue-XXX.svg", but "dist/red-XXX.svg" is also there yet not reachable from code.

System Info

npmPackages:
    vite: ^6 => 6.3.3

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) and removed pending triage labels Apr 28, 2025
@BerkliumBirb
Copy link
Author

Can't vite:asset use chunk.viteMetadata.importedAssets in generateBundle to handle unused assets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

2 participants