Skip to content

Broken eagerly imported assets tree shaking #19949

@BerkliumBirb

Description

@BerkliumBirb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-nice-to-haveNot breaking anything but nice to have (priority)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions