Skip to content

Unused assets left by code optimization #20209

@MattIPv4

Description

@MattIPv4

Bug Description

When using code optimization to drop unused code, assets that were emitted but no longer referenced are still emitted.

Link to Minimal Reproduction and step to reproduce

https://github.com/MattIPv4/webpack-asset-repro

  • npm ci
  • npm run build
  • ls dist/*.png
  • for each file.png, cat dist/main.js | grep <file.png>

One png should be referenced in dist/main.js, while the other won't be as it was used by dead code.

Expected Behavior

Assets that are emitted but later made unused by code optimization should be removed from the emitted assets

Actual Behavior

Assets are always emitted even if all references to them are dropped by code optimization

Environment

System:
    OS: macOS 26.1
    CPU: (14) arm64 Apple M4 Pro
    Memory: 97.52 MB / 24.00 GB
  Binaries:
    Node: 22.13.1 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/node
    npm: 10.9.2 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/npm
    pnpm: 10.20.0 - /Users/mattcowley/.local/state/fnm_multishells/85154_1765079840717/bin/pnpm
  Browsers:
    Chrome: 142.0.7444.177
    Firefox Developer Edition: 146.0
    Safari: 26.1
    Safari Technology Preview: 26.0
  Packages:
    webpack-cli: ^6.0.1 => 6.0.1

Is this a regression?

None

Last Working Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions