-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathastro.config.mjs
More file actions
executable file
·108 lines (105 loc) · 3.02 KB
/
astro.config.mjs
File metadata and controls
executable file
·108 lines (105 loc) · 3.02 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
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import tailwind from "@astrojs/tailwind";
import AutoImport from "astro-auto-import";
import { defineConfig } from "astro/config";
import remarkCollapse from "remark-collapse";
import remarkToc from "remark-toc";
import rehypeKatex from "rehype-katex";
import remarkMath from "remark-math";
import rehypeExternalLinks from "rehype-external-links";
import { fileURLToPath, URL } from "node:url";
// 获取环境变量
const NODE_ENV = process.env.NODE_ENV || 'development';
const isProduction = NODE_ENV === 'production';
const isDevelopment = NODE_ENV === 'development';
// 根据环境设置站点 URL
const getSiteUrl = () => {
switch (NODE_ENV) {
case 'production':
return "https://maplezz.com"; // 请替换为您的实际域名
case 'development':
case 'test':
default:
return "http://localhost:4321";
}
};
// https://astro.build/config
export default defineConfig({
site: getSiteUrl(),
base: "/",
trailingSlash: "ignore",
output: "static",
server: {
// 允许通过本机IP访问开发服务器
host: true, // 或者使用 '0.0.0.0'
port: 4321
},
build: {
// 静态站点构建优化
inlineStylesheets: "auto",
assets: "_astro",
// 启用并行构建以提升性能
concurrency: 4,
// 分割代码以减少单个文件大小
split: true
},
prefetch: {
// 在开发环境禁用预取以加快构建
prefetchAll: isProduction
},
integrations: [
react(),
tailwind({
applyBaseStyles: false, // 使用自定义的base样式
}),
AutoImport({
imports: ["@components/common/Button.astro", "@shortcodes/Accordion", "@shortcodes/Notice", "@shortcodes/Youtube", "@shortcodes/Tabs", "@shortcodes/Tab"]
}),
mdx()
],
markdown: {
remarkPlugins: [remarkToc, [remarkCollapse, {
test: "Table of contents"
}], remarkMath],
rehypePlugins: [
[rehypeKatex, {}],
[rehypeExternalLinks, {
target: "_blank",
rel: ["nofollow", "noopener", "noreferrer"],
test: (node) => {
// 只对外部链接应用,内部链接不受影响
const href = node.properties?.href;
if (!href) return false;
// 检查是否为外部链接
return href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//');
}
}]
],
shikiConfig: {
themes: { // https://shiki.style/themes
light: "github-light",
dark: "github-dark-dimmed",
}
},
extendDefaultPlugins: true
},
image: {
// 配置图片处理
remotePatterns: [{
protocol: "https"
}],
// 启用图片优化服务
service: {
entrypoint: "astro/assets/services/sharp"
},
// 图片优化配置
domains: [],
// 降低图片质量以加快构建速度
quality: isDevelopment ? 60 : 80,
// 支持的图片格式
formats: ["webp", "avif"],
// 启用图片缓存以加速重复构建
experimentalLayout: "constrained"
},
});