-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathastro.config.mjs
More file actions
163 lines (153 loc) · 5.96 KB
/
astro.config.mjs
File metadata and controls
163 lines (153 loc) · 5.96 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { resolve as resolvePath } from "node:path";
import { fileURLToPath } from "node:url";
import node from "@astrojs/node";
import sitemap from "@astrojs/sitemap";
import svelte, { vitePreprocess } from "@astrojs/svelte";
import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections";
import { pluginLineNumbers } from "@expressive-code/plugin-line-numbers";
import tailwindcss from "@tailwindcss/vite";
import { config as loadDotenv } from "dotenv";
import { defineConfig } from "astro/config";
import expressiveCode from "astro-expressive-code";
import icon from "astro-icon";
import { resolvePublicBaseUrl } from "./src/config/public-base-url.mjs";
import { pluginCustomCopyButton } from "./src/plugins/expressive-code/custom-copy-button.js";
import { pluginLanguageBadge } from "./src/plugins/expressive-code/language-badge.ts";
import { shouldIgnoreBuildWarning } from "./src/utils/vite-build-warning-filter.ts";
import {
rehypePlugins,
remarkPlugins,
} from "./src/server/markdown/pipeline.ts";
loadDotenv();
const resolvedPublicBaseUrl = resolvePublicBaseUrl(process.env);
const projectRootDir = fileURLToPath(new URL(".", import.meta.url));
// https://astro.build/config
export default defineConfig({
site: resolvedPublicBaseUrl.siteURL,
base: "/",
trailingSlash: "never",
devToolbar: {
enabled: false,
},
server: {
allowedHosts: true,
},
security: {
// Astro's built-in form-origin middleware compares Origin with
// Astro.url.origin before our BFF guard can account for reverse-proxy
// headers. Keep the project-level same-origin + CSRF + rate-limit guard
// as the write boundary so multipart uploads work behind Docker Caddy.
checkOrigin: false,
allowedDomains: [{ hostname: resolvedPublicBaseUrl.hostname }],
},
// server 模式只改变默认渲染策略;静态例外继续由显式 prerender 控制。
output: "server",
adapter: node({
mode: "standalone",
}),
prefetch: {
prefetchAll: false,
defaultStrategy: "hover",
},
integrations: [
icon(),
expressiveCode({
themes: ["github-light", "github-dark"],
plugins: [
pluginCollapsibleSections(),
pluginLineNumbers(),
pluginLanguageBadge(),
pluginCustomCopyButton(),
],
defaultProps: {
wrap: true,
overridesByLang: {
shellsession: { showLineNumbers: false },
bash: { frame: "code" },
shell: { frame: "code" },
sh: { frame: "code" },
zsh: { frame: "code" },
},
},
styleOverrides: {
codeBackground: "var(--codeblock-bg)",
borderRadius: "0.75rem",
borderColor: "none",
codeFontSize: "0.875rem",
codeFontFamily: "var(--font-mono)",
codeLineHeight: "1.5rem",
frames: {
editorBackground: "var(--codeblock-bg)",
terminalBackground: "var(--codeblock-bg)",
terminalTitlebarBackground: "var(--codeblock-bg)",
editorTabBarBackground: "var(--codeblock-bg)",
editorActiveTabBackground: "none",
editorActiveTabIndicatorBottomColor: "var(--primary)",
editorActiveTabIndicatorTopColor: "none",
editorTabBarBorderBottomColor: "var(--codeblock-bg)",
terminalTitlebarBorderBottomColor: "none",
},
textMarkers: {
delHue: 0,
insHue: 180,
markHue: 250,
},
},
frames: {
showCopyToClipboardButton: false,
},
}),
svelte({
preprocess: vitePreprocess(),
}),
sitemap(),
],
markdown: {
remarkPlugins,
rehypePlugins,
},
vite: {
resolve: {
alias: {
"@": resolvePath(projectRootDir, "src"),
"@components": resolvePath(projectRootDir, "src/components"),
"@assets": resolvePath(projectRootDir, "src/assets"),
"@constants": resolvePath(projectRootDir, "src/constants"),
"@utils": resolvePath(projectRootDir, "src/utils"),
"@i18n": resolvePath(projectRootDir, "src/i18n"),
"@layouts": resolvePath(projectRootDir, "src/layouts"),
},
},
plugins: [tailwindcss()],
build: {
// 静态资源处理优化,防止小图片转 base64 导致 HTML 体积过大(可选,根据需要调整)
assetsInlineLimit: 4096,
// Monaco 仅在发布编辑器页面按需加载,放宽提示阈值,避免对已知的大型惰性 chunk 反复报警。
chunkSizeWarningLimit: 3000,
rollupOptions: {
output: {
manualChunks(id) {
if (
id.includes(
"astro/dist/core/middleware/index.js",
) ||
id.includes(
"astro/dist/core/middleware/sequence.js",
)
) {
return "astro-middleware-core";
}
return undefined;
},
},
onwarn(warning, warn) {
// 仅收敛已确认无害的上游构建链噪音,其他 warning 继续原样透传。
if (shouldIgnoreBuildWarning(warning)) {
return;
}
warn(warning);
},
},
},
},
});