Skip to content
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

Why do output plugins run before input plugins? #3845

Closed
1 of 4 tasks
aleclarson opened this issue Oct 28, 2020 · 9 comments · Fixed by #4549
Closed
1 of 4 tasks

Why do output plugins run before input plugins? #3845

aleclarson opened this issue Oct 28, 2020 · 9 comments · Fixed by #4549

Comments

@aleclarson
Copy link
Contributor

aleclarson commented Oct 28, 2020

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?

Please Explain in Detail...

If both an input plugin and output plugin have a generateBundle hook, the output plugin's hook runs first.
Is there a reason for this?

Your Proposal for Changes

Run output plugins last (if possible?).

Or provide a method on PluginContext that allows a hook to postpone itself until other hooks for the same phase have finished, like this:

async generateBundle() {
  await this.postpone()
  // Do stuff after all non-postponed `generateBundle` hooks have finished.
}
@lukastaegert
Copy link
Member

Is there a reason why they should run last?

@aleclarson
Copy link
Contributor Author

aleclarson commented Oct 28, 2020

I'm creating an output plugin with some context that only exists after rollup(...) is called, so I can't add an input plugin by that time. It's for a feature in Vite.

Example: https://github.com/aleclarson/vite/blob/6ad0d33a258987d4f4389a9d179b9d45b5489781/src/node/build/index.ts#L565-L587

I also think it's less surprising to run output plugins last, since they are added after input plugins.

@aleclarson
Copy link
Contributor Author

I reworked the feature in Vite so I can add an input plugin, but I still think output plugins should run last. Not sure it's worth the breaking change or not, though.

@CxRes
Copy link

CxRes commented Jan 11, 2021

This both definitely confusing (undocumented) and definitely a problem (intuitive and possibly disruptive)!

I am generating two output bundles (a cjs and esm ie output is an Array) and want to run @rollup/plugin-html to generate html files for each bundle.

  • If I run this (even twice) as an input plugin, the bundles object in generateBundle hook does not contain information about the first output bundle.
  • If I run this as an output plugin (which imho is the intuitive thing to do), the bundle object in generateBundle hook does not contain information about the css files generated using rollup-plugin-styles because I guess it has not run yet.

Its taken me half a day to diagnose why something as simple is not working and then to find this comment ☹️

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #3846 as part of rollup@3.0.0-5. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-5 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #3846 as part of rollup@3.0.0-6. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-6 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #3846 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-7 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #3846 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #3846 as part of rollup@3.0.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants