2022-06-27 13:26:21 -05:00
|
|
|
import type { AstroIntegration } from 'astro';
|
|
|
|
import type { PrefetchOptions } from './client.js';
|
|
|
|
|
|
|
|
export default function (options: PrefetchOptions = {}): AstroIntegration {
|
|
|
|
return {
|
2022-06-30 12:53:01 -05:00
|
|
|
name: '@astrojs/prefetch',
|
2022-06-27 13:26:21 -05:00
|
|
|
hooks: {
|
|
|
|
'astro:config:setup': ({ updateConfig, addRenderer, injectScript }) => {
|
|
|
|
// Inject the necessary polyfills on every page (inlined for speed).
|
|
|
|
injectScript(
|
|
|
|
'page',
|
2022-06-27 13:28:16 -05:00
|
|
|
`import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(
|
|
|
|
options
|
|
|
|
)});`
|
2022-06-27 13:26:21 -05:00
|
|
|
);
|
2022-06-27 13:28:16 -05:00
|
|
|
},
|
|
|
|
},
|
2022-06-27 13:26:21 -05:00
|
|
|
};
|
|
|
|
}
|