You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The vite:manifest, vite:build-html, and vite:build-import-analysis plugins are accessing internal state from other plugins such as:
chunkToEmittedCssFileMap: managed by the vite:css-post plugin, maps output chunks to emitted css files
chunkToEmittedAssetsMap: managed by the vite:asset plugin, maps output chunks to emitted asset files
Also, vite:css-post is using registerAssetToChunk internally shared by vite:asset.
This state is necessary to infer the non-JS dependencies of individual chunks, and would be useful for third-party plugins such as those in Astro, îles, Vite Ruby, Laravel Vite, etc.
Suggested solution
Opening this issue to keep the conversation moving.
It would be nice to encapsulate the internals to simplify maintenance and future refactoring, but any change that exposes the data mentioned above would enable third-party plugins to achieve their goals.
Possible Implementations
Covering a few options we've talked about, some of these are not desirable:
Extend OutputChunk data
To include css and assets dependencies.
This way, we are making this data an explicit part of the dependency graph.
Each internal plugin must extend this API, the exposed methods would depend on which plugins are active for the current mode (development vs build) or configuration.
ElMassimo
changed the title
Create an internal API to obtain emitted assets
Create an internal API to access css and asset dependency info
Jan 25, 2022
ElMassimo
changed the title
Create an internal API to access css and asset dependency info
Allow third-party plugins to access css and asset dependency info
Jan 25, 2022
Clear and concise description of the problem
The
vite:manifest
,vite:build-html
, andvite:build-import-analysis
plugins are accessing internal state from other plugins such as:chunkToEmittedCssFileMap
: managed by thevite:css-post
plugin, maps output chunks to emitted css fileschunkToEmittedAssetsMap
: managed by thevite:asset
plugin, maps output chunks to emitted asset filesAlso,
vite:css-post
is usingregisterAssetToChunk
internally shared byvite:asset
.This state is necessary to infer the non-JS dependencies of individual chunks, and would be useful for third-party plugins such as those in Astro, îles, Vite Ruby, Laravel Vite, etc.
Suggested solution
Opening this issue to keep the conversation moving.
It would be nice to encapsulate the internals to simplify maintenance and future refactoring, but any change that exposes the data mentioned above would enable third-party plugins to achieve their goals.
Possible Implementations
Covering a few options we've talked about, some of these are not desirable:
Extend
OutputChunk
dataTo include
css
andassets
dependencies.This way, we are making this data an explicit part of the dependency graph.
See implementation in #6629.
Extend the
PluginContext
APIAdd additional methods to the
PluginContext
API that allow accessing the data (akin togetFileName
):ResolvedConfig
functionsHave each plugin inject methods in
ResolvedConfig
that can provide the necessary functionality without exposing the internal data structures:Downsides
Too much responsibility for
ResolvedConfig
, poor maintainability.Per-Plugin API
Expose an
api
in thevite:css-post
andvite:asset
plugins with respective functions to map chunks to files, and to register new dependencies.Downsides
Requires third-party plugins to obtain the
ResolvedConfig
, filterplugins
by name, and obtain the relevant one.The name of the plugin becomes an external-facing API, which is fragile.
Single API Plugin
Similar to the previous, but instead centralize all internal APIs in a single plugin:
Downsides
Each internal plugin must extend this API, the exposed methods would depend on which plugins are active for the current mode (development vs build) or configuration.
Additional context
Validations
The text was updated successfully, but these errors were encountered: