feat: add import.meta.resolve support for ESM config (bundle config loader)#20962
Merged
sapphi-red merged 3 commits intovitejs:mainfrom Oct 28, 2025
Conversation
This was referenced Oct 19, 2025
Member
|
Just a note, but in Vitest we noticed that |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for import.meta.resolve in ESM Vite configuration files by integrating the custom import meta resolver from the module runner. The implementation reuses the resolver logic previously added for runtime module evaluation and injects it into the bundled config files.
Key Changes
- Integrates
createImportMetaResolverand custom hook string from module-runner into the config bundler - Adds
import.meta.resolveto the list of replaced import.meta properties during config bundling - Includes test coverage for the new functionality with an ESM config fixture
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/vite/src/node/config.ts | Adds import.meta.resolve injection logic to bundleConfigFile with ESM/CJS detection |
| packages/vite/src/node/tests/fixtures/config/import-meta/vite.config.ts | Adds test case using import.meta.resolve |
| packages/vite/src/node/tests/fixtures/config/import-meta/package.json | Marks test fixture as ESM module |
| packages/vite/src/node/tests/config.spec.ts | Updates test to verify import.meta.resolve behavior |
| packages/vite/src/module-runner/importMetaResolver.ts | Exports reusable string template for import.meta.resolve injection |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
7 tasks
19 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds
import.meta.resolvesupport to bundle config loader, applying the same logic from #20260.This PR only adds support for ESM configs (config files ending with
.mjs/.mtsor hastype: modulein the closestpackage.json. Supporting this in CJS files requires a bit more code asimport.meta.resolveis not available in CJS files.fixes #20326