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

watch function based config #4037

Open
trhinehart-godaddy opened this issue Apr 8, 2021 · 5 comments
Open

watch function based config #4037

trhinehart-godaddy opened this issue Apr 8, 2021 · 5 comments

Comments

@trhinehart-godaddy
Copy link

Feature Use Case

using a rollup.config.js that exports a function (love this feature), I have async logic that generates meta information based on local/external endpoints that is eventually provided to a plugin.

Feature Proposal

when using watch flag, the function that generates the rollup configuration(s) ideally would run again, since the results are potentially different based on the change detected.

babel does something similar, and to combat performance issues exposes a cache feature exposed by an argument passed to the function itself. for backwards compatibility, the default cache could be set to the equivalent of "forever".

@lukastaegert
Copy link
Member

I see this as slightly problematic as this would mean re-creating all plugin instances on each run. This might make it hard to do any kind of watch optimizations in plugins. In any case, this could potentially cause quite a bit of churn in the plugin eco system of which I would be wary.
If you want to have different options per run, I would instead try writing an ad-hoc plugin using the options and outputOptions hooks first. https://rollupjs.org/guide/en/#options

@trhinehart-godaddy
Copy link
Author

I understand the perf issues around this, however a cache solution as mentioned would easily circumvent that. I'll give options a try but it'll require mutating a plugin option, which the only way I can think of doing that is applying the plugin during the options call? Or somehow using closure and having the plugin have a getter function to access some outside variable mutated by the options call?

also, found a minor bug: #4038

@trhinehart-godaddy
Copy link
Author

Attempting to use options, however the watch is only rebuilding the entries changed, which means the update to the options on the plugin(s) don't get re-executed on the rest of the chunks which could change their behavior.

@trhinehart-godaddy
Copy link
Author

@lukastaegert any other suggestions? I would essentially just want to re-invoke reloadConfigFile anytime there was a chokidar change. Is there anyway to get access to the chokidar instance watch creates? If I had access to the instance, I could emit a custom event that could provide an optional "force" flag to the reloadConfigFile function, assuming that would rebuild all entries.

@lukastaegert
Copy link
Member

The effect you want would be nearly identical to just running Rollup without watch on every change. Because no caching is possible if the configuration file, especially plugins, change. We can look if it is possible to simulate a changed config file on every update, but essentially you are preventing any of Rollup's watch optimizations. Until then, an external watcher that triggers Rollup could have the same effect.

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

No branches or pull requests

2 participants