mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
a23c69d0d0
* wip * done i think * Add changeset * Use hook instead * Reorder hooks [skip ci] * Update .changeset/eleven-pens-glow.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Fix run * Fix link * Add link Co-authored-by: Sarah Rainsberger <sarah11918@users.noreply.github.com> * More accurate migration [skip ci] --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Sarah Rainsberger <sarah11918@users.noreply.github.com>
1.5 KiB
1.5 KiB
astro |
---|
minor |
Deprecates the option for route-generating files to export a dynamic value for prerender
. Only static values are now supported (e.g. export const prerender = true
or = false
). This allows for better treeshaking and bundling configuration in the future.
Adds a new "astro:route:setup"
hook to the Integrations API to allow you to dynamically set options for a route at build or request time through an integration, such as enabling on-demand server rendering.
To migrate from a dynamic export to the new hook, update or remove any dynamic prerender
exports from individual routing files:
// src/pages/blog/[slug].astro
- export const prerender = import.meta.env.PRERENDER
Instead, create an integration with the "astro:route:setup"
hook and update the route's prerender
option:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { loadEnv } from 'vite';
export default defineConfig({
integrations: [setPrerender()],
});
function setPrerender() {
const { PRERENDER } = loadEnv(process.env.NODE_ENV, process.cwd(), '');
return {
name: 'set-prerender',
hooks: {
'astro:route:setup': ({ route }) => {
if (route.component.endsWith('/blog/[slug].astro')) {
route.prerender = PRERENDER;
}
},
},
};
}