mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
f21357b69d
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
30 lines
833 B
TypeScript
30 lines
833 B
TypeScript
import type { AstroIntegration, RouteData } from 'astro';
|
|
import { createRedirects } from './shared.js';
|
|
|
|
export function netlifyStatic(): AstroIntegration {
|
|
let _config: any;
|
|
return {
|
|
name: '@astrojs/netlify',
|
|
hooks: {
|
|
'astro:config:setup': ({ updateConfig }) => {
|
|
updateConfig({
|
|
build: {
|
|
// Do not output HTML redirects because we are building a `_redirects` file.
|
|
redirects: false,
|
|
},
|
|
});
|
|
},
|
|
'astro:config:done': ({ config }) => {
|
|
_config = config;
|
|
},
|
|
'astro:build:done': async ({ dir, routes }) => {
|
|
const mappedRoutes: [RouteData, string][] = routes.map((route) => [
|
|
route,
|
|
`/.netlify/static/`,
|
|
]);
|
|
const routesToDynamicTargetMap = new Map(Array.from(mappedRoutes));
|
|
await createRedirects(_config, routesToDynamicTargetMap, dir);
|
|
},
|
|
},
|
|
};
|
|
}
|