Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Run a plugin once another plugin has finished processing all the files in the transform hook? #19338

Closed
4 tasks done
basantech89 opened this issue Feb 2, 2025 · 5 comments
Closed
4 tasks done

Comments

@basantech89
Copy link

Description

I'm running a plugin in the transform hook that transforms all files and gathers some intel on the CSS styles that are used in the code; based on the intel, I need to transform all the files again. But I'm not able to find a way to process all the files again with another plugin once the previous plugin has finished transforming all the files in the transform hook.

Here is the plugin: plugin, I'm transforming the files in the transform hook with plugin1 that store some data on the css object, and then once all the files are processed by plugin1, I need to transform those files that were transformed by plugin1 with plugin2. The only way I was able to do this, is in the renderChunk hook, but it doesn't get invoked with the dev server.

Pl help.

Suggested solution

It'd be helpful if we can transform the files in another hook that were transformed with the transform hook.

Alternative

No response

Additional context

No response

Validations

@sapphi-red
Copy link
Member

This feels too specific to have in Vite core. If the two plugins are so tightly coupled, I think they should communicate directly, not through some mechanism provided by Vite.

@basantech89
Copy link
Author

but how will they communicate? since plugin2 needs to start transforming only when plugin1 has finished transforming all the files?

I would've run both plugins one after the other in the same transform hook for each file if the above were not the case. @sapphi-red

@userquin
Copy link
Contributor

userquin commented Feb 7, 2025

How do you know when the master plugin has finished processing all the files?

Instead using vite plugins, why not just add some minimal post-process interface to the plugin? Once the plugin finish the pre-processing in all targets it can just call all registered post-processes: these post-processes can be from user lang or registered from other vite plugins via Rollup direct communication api ( https://rollupjs.org/plugin-development/#direct-plugin-communication ), the plugin should expose the api to register the post-process entries.

@sapphi-red
Copy link
Member

I thought you know all the file names that plugin1 needs to process. But it seems you don't know it?

In that case, there's no way to know all the file names automatically.
In dev, this is because Vite doesn't have a concept of entrypoint in dev.
In build, this is because Rollup doesn't have an API to do that. You can try collecting the file names in hooks that runs before transform, but this is just a approximate. You can check rollup/rollup#4985 for some discussions about it.

@userquin
Copy link
Contributor

userquin commented Feb 7, 2025

Thx for the link

@vitejs vitejs locked and limited conversation to collaborators Feb 7, 2025
@patak-dev patak-dev converted this issue into discussion #19380 Feb 7, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants