Do plugins need to be of a single type? #4852
-
Coming from Rollup, a single plugin can involve multiple hooks. But looking at https://v2.parceljs.org/plugin-system/authoring-plugins/, it seems like Parcel plugins can only operate on a single hook. Is this limiting? Is there a way to create a plugin that's formed of multiple plugins? I haven't tried to write a Parcel plugin yet, so maybe it just isn't needed. But fwiw, when writing a "service worker plugin" for Rollup and webpack, we had to use multiple hooks each. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I'm not entirely sure what you mean with "can only operate on a single hook" as we don't really have a concept of hooks in Parcel as far as I know. We have built it in a way that each step of Parcel has a certain type of plugin, so if you need multiple "hooks" you should probably write multiple plugins. For your example as far as I quickly went through that talk it seems like a very basic plugin that's just a transformer plugin with a single "hook". We did try to make this logical so that you would rarely need something to span across multiple plugins, however this can still happen for slightly more advanced plugins like the react-refresh one, which spans across a runtime and transformer |
Beta Was this translation helpful? Give feedback.
-
The idea for this is that these "hooks" have nothing to do with each other. So by splitting them up, running them in parallel is easier and we can provide a more idiomatic interface (e.g. compared to Webpack)
Yes: https://v2.parceljs.org/plugin-system/configuration/ (we should probably put this into the "authoring plugins" page as well). For example, Preact's HMR implementation for Parcel (2 Transformer + 1 Runtime): Demo (you extend some other config than The config that bundles the other plugins: https://github.com/mischnic/preact-refresh/blob/dc2309c36048a34cf83bc6f2506b1d48518f97f2/packages/parcel-config/index.json |
Beta Was this translation helpful? Give feedback.
-
Boom, perfect. Thank you! |
Beta Was this translation helpful? Give feedback.
The idea for this is that these "hooks" have nothing to do with each other. So by splitting them up, running them in parallel is easier and we can provide a more idiomatic interface (e.g. compared to Webpack)
Yes: https://v2.parceljs.org/plugin-system/configuration/ (we should probably put this into the "authoring plugins" page as well).
For example, Preact's HMR implementation for Parcel (2 Transformer + 1 Runtime):
Demo (you extend some other config than
@parcel/config-default
) https://github.com/mischnic/preact-refresh/blob/dc2309c36048a34cf83bc6f2506b1d48518f97f2/packages/parcel-example/.parcelrcThe config that bu…