Open ashur opened 2 years ago
While I strongly agree that this functionality would be useful, I don't see the benefit of exposing such an event (@ashur if you have a usecase that can only be solved with such an event, could you maybe explain it in a little more detail?).
I would personally prefer a solution where it is possible for plugins to register routes and handlers with EleventyServe (my first thought was towards serverless functions) and to provide plugins also with a way to retrigger builds. That way you could start with something simpel like "rebuild every X seconds" and build as complex logic as you want.
That way you can have one API change and provide for way more usecases. Some other interesting ones that come to mind are:
For this solution we'd need to
Eleventy.restart
works to allow rebuilds from other sources than watchEleventy.restart
EleventyServe
instanceConsiderations
Doing this will take more work than what is proposed by @ashur, but will most likely result in a more flexible API covering this and many more usecases. This will also move functions currently only possible for Eleventy into the realm of plugins at the expense of expanding the API.
Summary
Gatsby has a handy development feature for refreshing data without having to stop and restart the local server.
Paired with a simple bookmarklet that POSTs to the endpoint, the feature allows developers to re-fetch data with a single click without leaving the browser — ex., to test content changes in a remote CMS.
Feature Request
It would be really helpful for clearing locally cached data if Eleventy added a hook for doing something similar.
For example, Eleventy configuration could accept a new event type that allows developers to define functions for refreshing data:
Ideally, these would only called if the feature is enabled (ex., by an environment variable as in Gatsby). After the refresh function has finished successfully, Eleventy would perform another build automatically, triggering a browser reload if applicable.
Alternatives
Some possible approaches that don't require native support from Eleventy:
eleventy --serve
that listens for data refresh requests; this would primarily be filesystem and process/command-line driven