RFC: Allow Plugins to Specify a Relative Order #13174
Replies: 0 comments 2 replies
-
I really like this proposal as it is very explicit in what your dependencies are (as opposed e.g. to the magic number proposal). But maybe
instead to allow for having multiple dependencies? One issue I foresee (that is not blocking) is that there is now the possibility to create impossible dependencies, which we need to handle in some way. E.g. There are more complex cases like this, but in the end, Rollup/Vite will basically need to create a directed graph of plugin dependencies and check if it has cycles. If not, we can order the plugins, otherwise we warn-and-ignore or throw. Following what has been done in There is another complexity hidden that we would need to figure out, imagine you have the following plugins:
Now we can resolve the dependencies, but we cannot satisfy the In general my feeling is that all of these are edge cases that actually should not occur, but we need to handle them. Maybe just throwing is actually a good option. |
Beta Was this translation helpful? Give feedback.
-
Summary
Allow plugins to specify an
order
relative to another plugin usingpre
andpost
.Basic Example
We can extend
enforce
ororder
from'pre' | 'post' | null
, to also support an object form:{ pre?: string, post?: string }
.A plugin can then use
enforce
ororder
to specify that it should run before or after another plugin, by specifying their name:Rollup Proposal: hook specific
Motivation
Some plugins in Vite and Rollup need to run before or after a specific plugin (i.e. before or after the Vue or Svelte compiler transforms).
Currently, Vite and Rollup do not provide an explicit API or plugins to collaborate with each other explicitly.
As a result, userland plugins are resorting to hacks and workarounds to achieve a better UX.
With the proposed extension, plugins like Vuetify's could ensure that they always work as expected.
This would enable better compatibility between plugins that interact or extend each other, and result in a better user experience by removing the need to order plugins manually (in cases like these).
Alternatives
This problem is not new, has always existed in Rollup, and was partially mitigated by
enforce
in Vite, but it still exists.As a result, there are different ways to workaround it, with varying degrees of UX and dependency on Vite's internals:
enforce
pre
orpost
, which works in simple cases, but can move the plugin earlier or later in the chain that it needs to be, and hides the dependency on a required pluginRelated Issues and RFCs:
Beta Was this translation helpful? Give feedback.
All reactions