Replies: 1 comment
-
PR with some of the ideas above (less ambitiously implemented) can be found here: withastro/astro#4765 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The Problem
The existing integration API is making simple file writing difficult.
If you want to create an integration that writes a file you currently have to do two completely different things to make it work in both ssg and dev/ssr modes. An example of this is the
@astrojs/image
integration that'astro:build:done'
to callwriteFile
for every image and'astro:config:setup'
toinjectRoute
and creates an endpoint that can return aResponse
on demand.Saying "I want to generate some files and write them to disk" should not require all this work. And, that work isn't obvious when reading the integration API documentation. There are many integrations, e.g.
astro-seo-images
, that just hook into'astro:build:done'
and don't support dev/ssr at all.Here are the problems I can think of, off the top of my head, that having a split API causes:
astro-seo-images
takes page routes as input so that it can screenshot the page. But, it has no API to cleanly access that page and it has no API to delete the page once it generates an image, so the page ends up in the final build output.Things to Support
I can think of two types of file-generating integrations that we'd want to support:
@astrojs/image
where the main entry point is a component. When the component is rendered it possibly needs to generate file[s]. These have arbitrary inputs (the props to the component) that can be anything.astro-seo-images
where the input is an existing static file or an Astro page (html or non-html). These integrations might transform the inputs (e.g. compress images) where the output replaces the input. They might be purely additive, where a new file is written but the old file is untouched.Solution Brainstorming
I feel confident I understand the problem but I don't at all feel comfortable proposing a specific solution. I don't really know Astro/Vite well enough. I can think out loud though:
For case 1 above, perhaps Astro can provide a file-generating integration API? It would do what
@astrojs/image
does internally: Astro can callwriteFile
in ssg and provide an endpoint in dev/ssr. All it would ask of the file integration is to provide buffers. That would handle the component-generating-static-files case.For the second case, Astro would need to provide an API that allowed the integration to specify bunch of options:
getStaticPaths
?)Response
Response
metadata, e.g. a cache key to enable caching of filesIn both cases, Astro has to own enumerating all the inputs and calling the integration to generate files for those inputs, in all modes: ssg/dev/ssr.
Beta Was this translation helpful? Give feedback.
All reactions