-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add sequential before build hook #2826
Comments
@guybedford, you've added |
Tricky. We could always just make the Any reason why the copying needs to happen at |
As an easter egg at the moment (official API hopefully upcoming), you can also add arbitrary files to a build without the need of a file operation by using
|
@lukastaegert I find it intuitive to do tasks not related to bundling in separate from bundling hooks, to kinda have a separation from bundling and other tasks. So, in my head the flow is - delete files, copy files, then generate bundle and write it. I actually tried to use I feel like I'm trying to hack hooks, which were designed to be part of bundling and not for doing outside tasks :) |
I have a small test with hooks, chunks and multiple targets, it gives me this: I feel like a global before and after hooks (on top and bottom of this list) would be a nice addition and already have use cases. What do you think? |
Unfortunately this is conceptually not possible. Rollup CLI is just a thin wrapper around Rollup's JavaScript API which does not know when you are finished calling
So going from there, I would put logic that is relevant for all outputs such as cleaning the |
@lukastaegert okay, so delete functionality can go to For copying, imagine this example: output: [
{
file: 'dist/file.commonjs.js',
format: 'commonjs'
},
{
file: 'dist/file.module.js',
format: 'module'
}
] So, they are both generated to the same place, This is the reason and use case I opened this issue. |
I understand that, but I do not know what a good solution would be, as the problem is performance vs ordering, which is why I wanted to point out existing alternatives for ordering two plugins, e.g. putting one in |
@lukastaegert yep, this is what I ended with, one in |
@vladshcherbin given the working workaround, shall we close this one? |
@shellscape I'm actually not sure. When I develop a plugin, I definitely feel the limitations of current plugin system, like this one where I have to choose hooks carefully because can't control the order of plugins execution or sync/async plugin execution. I'm still not happy with above workaround but it kinda works for now. This is related to another issue I subscribed to - #1148. So the main issue is not this one, it's just 1 of many which add difficulties in plugin creation. I feel like plugin system is better suited for plugins which target bundled files and plugins which target other tasks like copying need to use workarounds. Feel free to close this one if you feel it needs to, I just don't know where to subscribe or what issue to follow to see changes in plugin hooks. A lot of related issues were recently closed but no solution to any of them was found or added. 😢 |
I understand. We closed a bunch in the hopes that the authors or participants would speak up, or step up to help because we are short on help these days. I think we should keep this open and track it though given your follow up comments. 👍 |
There's currently no way to alter options in an async way. |
This should go into #3397 |
@lukastaegert I think we're still feeling this in rollup/plugins#203 (comment). Any suggestions for how to resolve that one? |
One possible solution might be to have an extra option in addition to plugins option: plugins: [...],
To allow plugins to run after all other plugins, we could introduce a special string 'other-plugins', which represent the other plugins (that all run async with each other): enforceBeforeBuildPluginOrder: [ 'cleanDist', 'other-plugins', 'autoGenerateSrc', 'typescript'], It the above example, the 'other-plugins' start after cleanDist, and all must finish before 'autoGenerateSrc' starts, which is then followed by 'typescript'. |
We have the same problem, but at the end of the build. We need to run three plugins in order at the end of our build, but don't have a way to do so. We can use As an alternative to adding an additional sequential hook, I wonder if it would be worth trying to come up with a way to opt some plugin hooks out of running in parallel. E.g. if I name my hook
|
Hey, 👋
Feature Use Case
Imagine 2 plugins: delete (deletes dist folder), copy (copies files in dist folder).
They need to be executed before build. Current
buildStart
hook seems like a good choice, but it runs in parallel. Delete plugin must run before copy and I can't find any other suitable hook for it.Feature Proposal
Add async, sequential hook which runs before build or make possible
buildStart
hook to execute some plugins sequentially.The text was updated successfully, but these errors were encountered: