refactor: use urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin#22962
Draft
sapphi-red wants to merge 1 commit into
Draft
refactor: use urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin#22962sapphi-red wants to merge 1 commit into
urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin#22962sapphi-red wants to merge 1 commit into
Conversation
graphite-app Bot
pushed a commit
to rolldown/rolldown
that referenced
this pull request
Jul 22, 2026
…o pass context to `resolveFileUrl` hook (#10297) This PR adds a new feature to `import.meta.ROLLDOWN_FILE_URL_<referenceId>`. Currently, these file URL references does not have a way to differentiate each references when `resolveFileUrl` hook is called. But that is sometimes needed. For example, in Vite, there are three cases: - The wasm plugin emits the reference to the wasm binary. In SSR, this reference to the wasm binary should be rendered in a way that accesses as a relative path (as it's a file read). But in other plugins, the wasm binary should be rendered as the URL that can be accessed from the browser (this may sound strange, but it's the current behavior). So the `import.meta.ROLLDOWN_FILE_URL_<referenceId>` needs to be differentiated with type it is. - Vite has `?inline` query which forces the asset to be output as `data` URL. The same asset can be imported with the query in some places while it can also be imported without the query in other places. This means the same asset needs to be referenced differently depending on the reference. - Vite never inlines assets specified as the entrypoint. This information is tied to a single reference. [rendered docs](https://github.com/rolldown/rolldown/blob/07-15-feat_import.meta.rolldown_file_url__referenceid___urlid_support_to_pass_context_to_resolvefileurl_hook/docs/apis/plugin-api/file-urls.md#passing-a-urlid) In this PR, I made the `urlId` generated on the plugin side, but maybe that should be generated on the Rolldown side so that a conflict never happens. This can be done by adding `this.generateFileUrlId`. The API can also be expanded to store the metadata in the Rolldown side. Currently, The metadata lives on the plugin side, so the referenceId emit and the `resolveFileUrl` hook needs to be coupled. This works for Vite's case, but won't work in general. For now, I think it's ok to go without it. refs vitejs/vite#22962
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.
Built on top of #22898
Part of the "Use of
import.meta.ROLLUP_FILE_URL_referenceId" in #22709 (comment)requires rolldown/rolldown#10297
WIP