-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat: add import.meta.resolve support for ESM config (bundle config loader)
#20962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add import.meta.resolve support for ESM config (bundle config loader)
#20962
Conversation
|
Just a note, but in Vitest we noticed that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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