Search code examples
rollup

How are the return promises from Rollup plugin hooks used?


I'm attempting my first plugin for Rollup. Reading over the plugin docs in the hooks section I can see that most of the hooks can return a promise. However I don't see how that promise can be used. Is it passed to the next hook? What am I missing here?


Solution

  • The rollup hook system calls into registered plugins in its many processing stages. Each stage consists of many rollup internal and plugin supplied promises. It chains promises together to process through all steps. That's the typical way an async Javascript system works. For example, your plugin can have a load hook, the hook can immediately return the contents of a file, or it can return a Promise that, at a later time, resolves to the contents; rollup will chain the Promise with more processing Promises, which will execute when the first Promise resolved. Tip: Read about async functions.