refactor: use urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin - #22962
Merged
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
sapphi-red
force-pushed
the
docs/plugin-asset-emitting
branch
from
July 31, 2026 07:54
896ac0a to
6d2a426
Compare
sapphi-red
force-pushed
the
refactor/use-rolldown-file-url-urlid
branch
from
July 31, 2026 07:55
29bc9b6 to
d0534b3
Compare
sapphi-red
force-pushed
the
docs/plugin-asset-emitting
branch
from
July 31, 2026 08:43
6d2a426 to
da62a7d
Compare
sapphi-red
force-pushed
the
refactor/use-rolldown-file-url-urlid
branch
from
July 31, 2026 08:43
d0534b3 to
f6bb73c
Compare
sapphi-red
marked this pull request as ready for review
July 31, 2026 09:53
sapphi-red
force-pushed
the
refactor/use-rolldown-file-url-urlid
branch
from
July 31, 2026 10:31
f6bb73c to
8494fab
Compare
bluwy
previously approved these changes
Aug 3, 2026
bluwy
left a comment
Member
There was a problem hiding this comment.
Maybe we could have rolldown support like this.getExtendedReferenceId in the future, we it handles this abstraction automatically in the future
sapphi-red
force-pushed
the
docs/plugin-asset-emitting
branch
2 times, most recently
from
August 21, 2026 11:15
9739718 to
dc83d01
Compare
sapphi-red
force-pushed
the
refactor/use-rolldown-file-url-urlid
branch
from
August 21, 2026 11:17
8494fab to
a997819
Compare
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.
Part of the "Use of
import.meta.ROLLUP_FILE_URL_referenceId" in #22709 (comment)requires rolldown/rolldown#10297implementedReplaces the
__VITE_WASM_INIT__hack withurlIdfeature in Rolldown.http://rolldown.rs/apis/plugin-api/file-urls#passing-a-urlid