Feature Use Case
In Vite we are currently using our own scheme when emitting assets. Instead of import.meta.ROLLUP_FILE_URL_referenceId, we have __VITE_ASSET_referenceId__. The original reasons this was created has been resolved by:
We are exploring simplifying some of Vite's code to use more of Rollup standard paths to help with compatibility with both config options and Rollup plugins. See as an example:
I think we can't directly use import.meta.ROLLUP_FILE_URL_referenceId because we are emitting assets that are referenced in CSS files too. See for example here where we replace the __VITE_ASSET_referenceId__ in the renderChunk hook:
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/asset.ts#L70
// Urls added with JS using e.g.
// imgElement.src = "__VITE_ASSET__5aa0ddc0__" are using quotes
// Urls added in CSS that is imported in JS end up like
// var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aa0ddc0__)}\n";
We also have an API to modify these asset URL references that unifies handling across JS, HTML, and CSS, and both emitted assets and public assets (a feature of Vite where files in a specific folder are copied as is to the dist folder). See docs for renderBuiltUrl here. This API is similar to resolveFileUrl.
As part of renderBuiltUrl, we are forced to recreate some of what resolveFileUrl already does. See Vite inlining some Rollup functions from here.
My current thinking is that at least for Vite 4, we aren't going to drop our current asset referencing scheme. But I'm trying to see if we should convert __VITE_ASSET__referenceId__ to import.meta.ROLLUP_FILE_URL_referenceId for JS chunks when we are generating relative URLs to avoid duplicating the above functions and to give users a way to configure the way these URLs at runtime are generated using the standard resolveFileUrl.
Feature Proposal
I think to be able to do this, we need a new prepareChunk hook that will let us process our own asset reference scheme and in some cases replace our placeholders with import.meta.ROLLUP_FILE_URL_referenceId, before resolveFileUrl is called for the chunk.
I don't know if this is enough justification for a new hook. If not, we could see if there is a way to call resolveFileUrl and the standard import.meta.ROLLUP_FILE_URL_referenceId handling on our side during renderChunk. I don't see an easy way to do this without exposing more internals from Rollup though.
Feature Use Case
In Vite we are currently using our own scheme when emitting assets. Instead of
import.meta.ROLLUP_FILE_URL_referenceId, we have__VITE_ASSET_referenceId__. The original reasons this was created has been resolved by:We are exploring simplifying some of Vite's code to use more of Rollup standard paths to help with compatibility with both config options and Rollup plugins. See as an example:
I think we can't directly use
import.meta.ROLLUP_FILE_URL_referenceIdbecause we are emitting assets that are referenced in CSS files too. See for example here where we replace the__VITE_ASSET_referenceId__in therenderChunkhook:https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/asset.ts#L70
We also have an API to modify these asset URL references that unifies handling across JS, HTML, and CSS, and both emitted assets and public assets (a feature of Vite where files in a specific folder are copied as is to the dist folder). See docs for
renderBuiltUrlhere. This API is similar toresolveFileUrl.As part of
renderBuiltUrl, we are forced to recreate some of whatresolveFileUrlalready does. See Vite inlining some Rollup functions from here.My current thinking is that at least for Vite 4, we aren't going to drop our current asset referencing scheme. But I'm trying to see if we should convert
__VITE_ASSET__referenceId__toimport.meta.ROLLUP_FILE_URL_referenceIdfor JS chunks when we are generating relative URLs to avoid duplicating the above functions and to give users a way to configure the way these URLs at runtime are generated using the standardresolveFileUrl.Feature Proposal
I think to be able to do this, we need a new
prepareChunkhook that will let us process our own asset reference scheme and in some cases replace our placeholders withimport.meta.ROLLUP_FILE_URL_referenceId, beforeresolveFileUrlis called for the chunk.I don't know if this is enough justification for a new hook. If not, we could see if there is a way to call
resolveFileUrland the standardimport.meta.ROLLUP_FILE_URL_referenceIdhandling on our side duringrenderChunk. I don't see an easy way to do this without exposing more internals from Rollup though.