Skip to content

There's good no way to run after VITE_PRELOAD gets handled. Add bundleComplete hook? #16173

@wmertens

Description

@wmertens

Describe the bug

I have a plugin that post-processes the built files for i18n using the generateBundle hook, but in recent Vite versions it runs before Vite replaces the VITE_PRELOAD strings.

The importanalysis plugin always runs after user defined plugins:

...postPlugins,
...buildPlugins.post,
// internal server-only plugins are always applied after everything else
...(isBuild
? []
: [
clientInjectionsPlugin(config),
cssAnalysisPlugin(config),
importAnalysisPlugin(config),
]),

The reason I picked generateBundle is so that I don't have to worry about where the files are stored. writeBundle doesn't get called when using the API and closeBundle doesn't seem to have the information to find the built files.

Should there be one more plugin hook, e.g. bundleComplete? Or should I be doing the post-processing differrently?

Reproduction

https://github.com/wmertens/compiled-i18n/blob/e33db19080efbe5d02bdad691cf8e71a250158a9/src/vite.ts#L251-L276

Steps to reproduce

Use compiled-i18n in a project, bundle it, and notice that VITE_PRELOAD is still present in the i18n-ed versions.

System Info

System:
    OS: Linux 6.1 NixOS 24.05 (Uakari) 24.05 (Uakari)
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 3.73 GB / 15.20 GB
    Container: Yes
    Shell: 5.2.26 - /run/current-system/sw/bin/bash
  Binaries:
    Node: 20.9.0 - /nix/store/a1hckfqzyys4rfgbdy5kmb5w0zdr55i5-nodejs-20.9.0/bin/node
    npm: 10.1.0 - /nix/store/a1hckfqzyys4rfgbdy5kmb5w0zdr55i5-nodejs-20.9.0/bin/npm
    pnpm: 8.15.0 - ~/bin/pnpm
  npmPackages:
    vite: ^5.1.5 => 5.1.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions