Skip to content

Binary file corruption: unplugin treats binary files as text #524

Description

@Loccko

Environment

  • platform: all
  • unplugin version: 1.16.1
  • nodejs: 20.19.2
  • package manager: npm@10.8.2

Reproduction

Repo: https://github.com/Loccko/unplugin-webpack-issues/tree/main
To reproduce:

  1. Clone
  2. npm ci
  3. npm run build:webpack
  4. Try to open images/font from dist folder

Describe the bug

When using @intlify/unplugin-vue-i18n, unplugin corrupts all binary files (e.g., .jpg, .png, .svg) in the project, which then cannot be used in Vue components.

The root cause is unplugin/dist/webpack/loaders/load.js, which during execution calls the loader from @intlify/unplugin-vue-i18n. This loader does nothing with the source of these files (since the loader's condition check doesn't match). Subsequently, unplugin/dist/webpack/loaders/load checks the result of the unplugin-vue-i18n loader execution, which is undefined, and unplugin/dist/webpack/loaders/load calls the callback with the original input source.

Debug Screenshot 3

Original code: https://github.com/unjs/unplugin/blob/v1.16.1/src/webpack/loaders/load.ts

Since unplugin/dist/webpack/loaders/load.js lacks the raw = true variable, webpack treats the source as regular text content and attempts to process it as text rather than binary data.
Info: https://webpack.js.org/api/loaders/#raw-loader

This results in corruption of all binary files, leading to broken image and font files that cannot be used.

Note: This issue appears to be relevant for both unplugin@1.x.x and unplugin@2.x.x, as both major versions lack this variable.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions