Back to all fixes
CuratedTypeScriptVite 8local

import.meta.glob no longer emits unused imported assets in Vite 8 (breaks Laravel plugin asset globbing)

Problem

Code like `import.meta.glob(['../images/**'])` (without `eager: true`, value not otherwise used) stops causing those asset files to be emitted in the build output under Vite 8/Rolldown, whereas Vite 7/Rollup emitted them. This broke laravel-vite-plugin's approach of using `import.meta.glob` purely to register a directory of assets as build inputs. Root cause: Rollup does not eliminate `/* #__PURE__ */`-marked calls before scanning a file's imports, so unused glob imports still got scanned and their referenced files emitted; Rolldown removes the pure call first, so the imports are never scanned and the assets are never emitted.

Solution

typescript
Confirmed as an intentional behavior difference, not a bug to be reverted - Vite maintainer sapphi-red confirmed the correct fix is to explicitly mark files as build entries rather than rely on the `import.meta.glob` side effect. Two confirmed approaches:
1. Force usage with `eager: true` (works today per maintainer, but not guaranteed to keep working).
2. Better: register assets via `emitFile` in a plugin's `buildStart` hook:
```js
function thePlugin(assets) {
  return {
    name: 'p',
    apply: 'build',
    buildStart() {
      const files = glob(assets)
      for (const file of files) this.emitFile({ type: 'chunk', id: file })
      // also watch the directories covered by the glob
    }
  }
}
```
This was the direction laravel-vite-plugin adopted (via a new `assets` config option) instead of relying on glob-for-side-effect.