-
Notifications
You must be signed in to change notification settings - Fork 1
/
adds-to-head-integration.ts
45 lines (39 loc) · 1.4 KB
/
adds-to-head-integration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// add integration file so that svelte-check doesn't complain
// https://github.com/lilnasy/gratelets/blob/main/packages/adds-to-head/integration.ts
import type { AstroIntegration } from "astro";
import url from "node:url";
export default function (): AstroIntegration {
return {
name: "adds-to-head",
hooks: {
"astro:config:setup"({ config, updateConfig, logger }) {
const rootPath = url.fileURLToPath(config.root).replaceAll("\\", "/");
updateConfig({
vite: {
plugins: [
{
name: "adds-to-head",
transform(code, id) {
if (id.startsWith(rootPath) === false) return;
const moduleInfo = this.getModuleInfo(id);
if (moduleInfo === undefined || moduleInfo === null) return;
const metadata = moduleInfo?.meta?.astro;
if (metadata === undefined) return;
if (
code.includes("export const addsToHead = true;") ||
code.includes("export let addsToHead = true;")
) {
logger.debug(
`${id.slice(rootPath.length)} will now propagate assets.`,
);
metadata.propagation = "self";
}
},
},
],
},
});
},
},
};
}