-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathastro.config.mjs
More file actions
153 lines (153 loc) · 3.71 KB
/
astro.config.mjs
File metadata and controls
153 lines (153 loc) · 3.71 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
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
import tailwind from '@astrojs/tailwind';
import react from '@astrojs/react';
import partytown from '@astrojs/partytown';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
//记得修改,和robots一样
const SITE_URL = 'https://dh.zywe.de';
const sitemapConfig = {
filter: (page) => {
const excludedPaths = [
'/xw_assets/',
'/node_modules/',
];
return !excludedPaths.some(path => page.includes(path));
},
customPages: [],
serialize: (item) => {
let priority = 0.7;
let changefreq = 'monthly';
if (item.url === SITE_URL || item.url === `${SITE_URL}/`) {
priority = 1.0;
changefreq = 'weekly';
} else if (item.url.startsWith(SITE_URL)) {
priority = 0.9;
}
return {
url: item.url,
changefreq,
priority,
};
},
i18n: {
defaultLocale: 'zh-CN',
locales: {
'zh-CN': 'zh-CN'
},
},
};
export default defineConfig({
site: SITE_URL,
output: 'static',
devToolbar: {
enabled: false,
},
build: {
assets: 'xw_assets',
emptyOutDir: true,
inlineStylesheets: 'auto',
split: true,
rollupOptions: {
output: {
manualChunks: {
'vendor-core': ['astro'],
'vendor-ui': ['tailwindcss'],
'react-core': ['react', 'react-dom'],
'react-jsx': ['react/jsx-runtime'],
},
},
plugins: [
{
name: 'safe-html-comment-remover',
generateBundle(options, bundle) {
if (process.env.NODE_ENV === 'production') {
Object.keys(bundle).forEach(fileName => {
if (fileName.endsWith('.html')) {
const htmlAsset = bundle[fileName];
if (htmlAsset.type === 'asset' && typeof htmlAsset.source === 'string') {
let content = htmlAsset.source;
content = content
.replace(/^\s*<!--[\s\S]*?-->\s*$/gm, '')
.replace(/^\s*<!--[\s\S]*?-->/gm, '')
.replace(/<!--[\s\S]*?-->\s*$/gm, '')
.replace(/<!--astro:end-->/g, '')
.replace(/<!--\s*[^>\n\r]{1,80}\s*-->/g, '');
htmlAsset.source = content;
}
}
});
}
}
}
]
},
},
compressHTML: true,
integrations: [
tailwind({
applyBaseStyles: false,
}),
react(),
sitemap(sitemapConfig),
partytown({
config: {
debug: false,
forward: ['dataLayer.push', 'gtag'],
}
})
],
image: {
service: {
entrypoint: 'astro/assets/services/sharp',
},
responsiveStyles: true,
layout: 'constrained',
},
vite: {
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
fs: {
strict: true,
},
},
optimizeDeps: {
include: ['react', 'react-dom'],
exclude: ['astro'],
},
build: {
cssCodeSplit: true,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log', 'console.info'],
passes: 2,
},
mangle: {
safari10: true,
},
format: {
comments: false,
},
},
assetsInlineLimit: 4096,
chunkSizeWarningLimit: 1000,
reportCompressedSize: false,
},
css: {
devSourcemap: false,
},
},
server: {
host: '0.0.0.0',
port: 4321,
},
});