Skip to content

refactor: use urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin - #22962

Merged
sapphi-red merged 1 commit into
mainfrom
refactor/use-rolldown-file-url-urlid
Aug 21, 2026
Merged

refactor: use urlId of import.meta.ROLLDOWN_FILE_URL in wasm plugin#22962
sapphi-red merged 1 commit into
mainfrom
refactor/use-rolldown-file-url-urlid

Conversation

@sapphi-red

@sapphi-red sapphi-red commented Jul 17, 2026

Copy link
Copy Markdown
Member

Part of the "Use of import.meta.ROLLUP_FILE_URL_referenceId" in #22709 (comment)

requires rolldown/rolldown#10297 implemented

Replaces the __VITE_WASM_INIT__ hack with urlId feature in Rolldown.
http://rolldown.rs/apis/plugin-api/file-urls#passing-a-urlid

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
sapphi-red force-pushed the docs/plugin-asset-emitting branch from 896ac0a to 6d2a426 Compare July 31, 2026 07:54
@sapphi-red
sapphi-red force-pushed the refactor/use-rolldown-file-url-urlid branch from 29bc9b6 to d0534b3 Compare July 31, 2026 07:55
@sapphi-red
sapphi-red force-pushed the docs/plugin-asset-emitting branch from 6d2a426 to da62a7d Compare July 31, 2026 08:43
@sapphi-red
sapphi-red force-pushed the refactor/use-rolldown-file-url-urlid branch from d0534b3 to f6bb73c Compare July 31, 2026 08:43
@sapphi-red sapphi-red added the p3-significant High priority enhancement (priority) label Jul 31, 2026
@sapphi-red sapphi-red added this to the 8.3 milestone Jul 31, 2026
@sapphi-red
sapphi-red marked this pull request as ready for review July 31, 2026 09:53
@sapphi-red
sapphi-red force-pushed the refactor/use-rolldown-file-url-urlid branch from f6bb73c to 8494fab Compare July 31, 2026 10:31
bluwy
bluwy previously approved these changes Aug 3, 2026

@bluwy bluwy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have rolldown support like this.getExtendedReferenceId in the future, we it handles this abstraction automatically in the future

@sapphi-red
sapphi-red force-pushed the docs/plugin-asset-emitting branch 2 times, most recently from 9739718 to dc83d01 Compare August 21, 2026 11:15
@sapphi-red
sapphi-red force-pushed the refactor/use-rolldown-file-url-urlid branch from 8494fab to a997819 Compare August 21, 2026 11:17
Base automatically changed from docs/plugin-asset-emitting to main August 21, 2026 11:17
@sapphi-red
sapphi-red dismissed bluwy’s stale review August 21, 2026 11:17

The base branch was changed.

@sapphi-red
sapphi-red merged commit 92bd2a7 into main Aug 21, 2026
15 of 16 checks passed
@sapphi-red
sapphi-red deleted the refactor/use-rolldown-file-url-urlid branch August 21, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p3-significant High priority enhancement (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants