Skip to content

Commit b80928f

Browse files
Nikola HristovNikola Hristov
authored andcommitted
1 parent 1ea5322 commit b80928f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

astro.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,26 @@ export default (await import("astro/config")).defineConfig({
4242
devSourcemap: true,
4343
transformer: "postcss",
4444
},
45+
plugins: [
46+
{
47+
name: "crossorigin",
48+
transform(code, id, options) {
49+
return code
50+
.replace(/<script/g, '<script crossorigin="anonymous"')
51+
.replace(
52+
/<link[^>]*(?=.*rel="preload")(?=.*href="[^"]*\.js")(?=.*as="script")[^>]*/g,
53+
'$& crossorigin="anonymous"',
54+
)
55+
.replace(
56+
/<link[^>]*(?=.*rel="preload")(?=.*as="font")[^>]*/g,
57+
'$& crossorigin="anonymous"',
58+
)
59+
.replace(
60+
/<link[^>]*(?=.*rel="stylesheet")(?=.*href="https?:\/\/[^"]*")[^>]*/g,
61+
'$& crossorigin="anonymous"',
62+
);
63+
},
64+
},
65+
],
4566
},
4667
}) as typeof defineConfig;

0 commit comments

Comments
 (0)