1 import { defineConfig } from 'astro/config'
2 import mdx from '@astrojs/mdx'
3 import sitemap from '@astrojs/sitemap'
4 import remarkMath from 'remark-math'
5 import remarkDirective from 'remark-directive'
6 import rehypeKatex from 'rehype-katex'
7 import remarkEmbeddedMedia from './src/plugins/remark-embedded-media.mjs'
8 import remarkReadingTime from './src/plugins/remark-reading-time.mjs'
9 import rehypeCleanup from './src/plugins/rehype-cleanup.mjs'
10 import rehypeImageProcessor from './src/plugins/rehype-image-processor.mjs'
11 import rehypeCopyCode from './src/plugins/rehype-copy-code.mjs'
12 import remarkTOC from './src/plugins/remark-toc.mjs'
13 import { SITE } from './src/config'
14 import path from 'path'
15 import tailwindcss from '@tailwindcss/vite'
16 import node from '@astrojs/node'
17
18 export default defineConfig({
19 site: SITE.website,
20 base: '/',
21
22 devToolbar: {
23 enabled: false
24 },
25
26 output: 'server',
27
28 build: {
29 inlineStylesheets: 'auto'
30 },
31
32 image: {
33 service: {
34 entrypoint: 'astro/assets/services/sharp'
35 }
36 },
37
38 markdown: {
39 shikiConfig: {
40 theme: 'css-variables',
41 wrap: false
42 },
43 remarkPlugins: [remarkMath, remarkDirective, remarkEmbeddedMedia, remarkReadingTime, remarkTOC],
44 rehypePlugins: [rehypeKatex, rehypeCleanup, rehypeImageProcessor, rehypeCopyCode]
45 },
46
47 integrations: [mdx(), sitemap()],
48
49 vite: {
50 resolve: {
51 alias: {
52 '@': path.resolve('./src')
53 }
54 },
55
56 build: {
57 rollupOptions: {
58 output: {
59 // Function form so externalised modules (e.g. katex in the SSR
60 // server build) are skipped instead of erroring; the client build
61 // still gets the vendor chunks where these modules are bundled.
62 manualChunks(id) {
63 if (id.includes('node_modules/katex')) return 'vendor-katex'
64 if (
65 id.includes('node_modules/reading-time') ||
66 id.includes('node_modules/mdast-util-to-string')
67 )
68 return 'vendor-utils'
69 }
70 }
71 }
72 },
73
74 optimizeDeps: {
75 include: ['katex', 'reading-time']
76 },
77
78 plugins: [tailwindcss()]
79 },
80
81 adapter: node({
82 mode: 'middleware'
83 })
84 })