0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/netlify/src/integration-static.ts
Emanuele Stoppa f21357b69d
feat(@astrojs/netlify): add build.split support (#7615)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
2023-07-13 09:21:33 +01:00

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);
},
},
};
}