Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Dec 19, 2024
1 parent ed0cc8a commit d006362
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,26 @@ export default (await import("astro/config")).defineConfig({
devSourcemap: true,
transformer: "postcss",
},
plugins: [
{
name: "crossorigin",
transform(code, id, options) {
return code
.replace(/<script/g, '<script crossorigin="anonymous"')
.replace(
/<link[^>]*(?=.*rel="preload")(?=.*href="[^"]*\.js")(?=.*as="script")[^>]*/g,
'$& crossorigin="anonymous"',
)
.replace(
/<link[^>]*(?=.*rel="preload")(?=.*as="font")[^>]*/g,
'$& crossorigin="anonymous"',
)
.replace(
/<link[^>]*(?=.*rel="stylesheet")(?=.*href="https?:\/\/[^"]*")[^>]*/g,
'$& crossorigin="anonymous"',
);
},
},
],
},
}) as typeof defineConfig;

0 comments on commit d006362

Please sign in to comment.