New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Add flag when emitting assets to not emit files that are not referenced in the output #4774
Comments
This issue has been resolved via #4805 as part of rollup@3.11.0. You can test it via |
But is there a way/option to emit assets that are not referenced? |
Of course, just do not add |
I'm using astro for my project, which uses vite for build. How do I configure "needsCodeReference" in rollout options? astro.config.mjs
|
Only the plugin emitting the asset can configure it. In order to emit assets yourself, you need to write a plugin. But outside a plugin, you would not have access to the file reference id anyway, so this whole thing only makes sense in a plugin context. |
Feature Use Case
Currently, it is possible that an asset is emitted, but the usage of that asset is removed by tree-shaking. E.g. in the original code we have something like
Now one plugin resolves
asset
asimport.meta.ROLLUP_FILE_URL_abc123
and another plugin replacesCOMPILER_FLAG
withfalse
. In that scenario, the file would still be emitted but it is not referenced.Feature Proposal
Add a new property
needsCodeReference: boolean
toEmittedAsset
. If it is set totrue
, then the asset is only emitted if at least one correspondingimport.meta.ROLLUP_FILE_URL_referenceId
can be found in the emitted chunks.If the flag is not provided, it is treated as
false
for backwards compatibility.See also #4761 for another issue that is addressed by this.
Note: Assets can be deduplicated if they have the source. In that case, several reference ids can reference the same asset. In that scenario, the usage of one of the reference ids is of course enough for the asset to be emitted.
The text was updated successfully, but these errors were encountered: