vite
vite copied to clipboard
fix: avoid using `import.meta.url` for relative assets if output is not ESM (fixes #9297)
Description
We inject import.meta.url
in renderChunk
hook when relative base. Rollup replaces them depending on the output module type (ESM, CJS, System, ...). But that replace happens before renderChunk
hook (during resolveImportMeta
hook).
So if we inject import.meta.url
in renderChunk
these won't be replaced by Rollup.
This PR changes the injected value depending on the output module type.
fixes #9297
Additional context
Related rollup implementation: https://github.com/rollup/rollup/pull/2164
Related rollup hook: https://rollupjs.org/guide/en/#resolveimportmeta (this is called before renderChunk
hook)
What is the purpose of this pull request?
- [x] Bug fix
- [ ] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines.
- [x] Read the Pull Request Guidelines and follow the Commit Convention.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123
). - [x] Ideally, include relevant tests that fail without this PR but pass with it.
~~Instead of this, maybe we should inject a different value for import.meta.url
depending on output format.~~ done
I think this is important enough to get in a patch, we can test with this and other related PRs with vite-ecosystem-ci before moving forward.
Hey 👋! @patak-dev Planning the next release? 😄
This PR was not found in 3.0.5
Yes, we merged this one after 3.0.5, we will do another patch in the next days
@patak-dev is there any timeline when will this fix be released?
Before the end of the week @kishore-rajendran
thanks for the update @patak-dev 😁