| 1 | import { defineConfig } from "astro/config"; |
| 2 | import { unified } from "@astrojs/markdown-remark"; |
| 3 | import rehypeExternalLinks from "rehype-external-links"; |
| 4 | import rehypeShikiFromHighlighter from "@shikijs/rehype/core"; |
| 5 | import cloudflare from "@astrojs/cloudflare"; |
| 6 | import mdx from "@astrojs/mdx"; |
| 7 | import tailwindcss from "@tailwindcss/vite"; |
| 8 | import sitemap from "@astrojs/sitemap"; |
| 9 | import { fileURLToPath } from "url"; |
| 10 | import path from "path"; |
| 11 | import { createDarkmatterHighlighter, THEME_NAME } from "./scripts/shiki-setup.mjs"; |
| 12 | |
| 13 | const highlighter = createDarkmatterHighlighter(); |
| 14 | |
| 15 | const root = path.dirname(fileURLToPath(import.meta.url)); |
| 16 | const emptyShikiTheme = path.resolve(root, "./scripts/empty-shiki-theme.mjs"); |
| 17 | |
| 18 | // https://astro.build/config |
| 19 | export default defineConfig({ |
| 20 | site: "https://stevedylan.dev", |
| 21 | outDir: "dist", |
| 22 | compressHTML: true, |
| 23 | image: { |
| 24 | domains: ["kagifeedback.org", "api.iconify.design", "files.stevedylan.dev"], |
| 25 | }, |
| 26 | markdown: { |
| 27 | syntaxHighlight: false, |
| 28 | processor: unified({ |
| 29 | rehypePlugins: [ |
| 30 | [(opts) => rehypeShikiFromHighlighter(highlighter, opts), { theme: THEME_NAME, defaultLanguage: "text", fallbackLanguage: "text", addLanguageClass: true }], |
| 31 | [rehypeExternalLinks, { target: "_blank", rel: ["noopener", "noreferrer"] }], |
| 32 | ], |
| 33 | }), |
| 34 | }, |
| 35 | prefetch: true, |
| 36 | integrations: [mdx(), sitemap()], |
| 37 | vite: { |
| 38 | plugins: [tailwindcss()], |
| 39 | resolve: { |
| 40 | alias: [ |
| 41 | { find: /^@shikijs\/themes\/[^/]+$/, replacement: emptyShikiTheme }, |
| 42 | { find: /^@shikijs\/themes\/dist\/.+\.mjs$/, replacement: emptyShikiTheme }, |
| 43 | { find: "@/components", replacement: path.resolve(root, "./src/components") }, |
| 44 | { find: "@/layouts", replacement: path.resolve(root, "./src/layouts") }, |
| 45 | { find: "@/utils", replacement: path.resolve(root, "./src/utils/index.ts") }, |
| 46 | { find: "@/stores", replacement: path.resolve(root, "./src/stores") }, |
| 47 | { find: "@/data", replacement: path.resolve(root, "./src/data") }, |
| 48 | { find: "@/assets", replacement: path.resolve(root, "./src/assets") }, |
| 49 | ], |
| 50 | extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".astro"], |
| 51 | }, |
| 52 | ssr: { |
| 53 | external: [ |
| 54 | "node:path", |
| 55 | "node:fs", |
| 56 | "node:fs/promises", |
| 57 | "node:url", |
| 58 | "node:http2", |
| 59 | "node:buffer", |
| 60 | "node:crypto", |
| 61 | "path", |
| 62 | "fs", |
| 63 | "url", |
| 64 | "os", |
| 65 | "child_process", |
| 66 | "crypto", |
| 67 | "tty", |
| 68 | "worker_threads", |
| 69 | "satteri", |
| 70 | "@astrojs/markdown-satteri", |
| 71 | "@napi-rs/wasm-runtime", |
| 72 | "sharp", |
| 73 | ], |
| 74 | }, |
| 75 | build: { |
| 76 | rollupOptions: { |
| 77 | external: [ |
| 78 | "satteri", |
| 79 | "@astrojs/markdown-satteri", |
| 80 | "@napi-rs/wasm-runtime", |
| 81 | "sharp", |
| 82 | ], |
| 83 | }, |
| 84 | }, |
| 85 | optimizeDeps: { |
| 86 | exclude: ["sharp"], |
| 87 | }, |
| 88 | }, |
| 89 | output: "static", |
| 90 | adapter: cloudflare({ |
| 91 | imageService: "compile" |
| 92 | }), |
| 93 | }); |