-
Notifications
You must be signed in to change notification settings - Fork 0
/
astro.config.mjs
165 lines (146 loc) · 4.58 KB
/
astro.config.mjs
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
164
165
import node from "@astrojs/node";
import prefetch from "@astrojs/prefetch";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import vercel from "@astrojs/vercel/serverless";
import Compress from "astro-compress";
import { VitePWA } from "vite-plugin-pwa";
import { defineConfig } from "astro/config";
import { manifest, seoConfig } from "./src/utils/seo-config";
const isDocker = process.env.CONTAINER === "true";
const isDev = process.env.NODE_ENV === "development";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: !isDocker
? vercel({
edgeMiddleware: {
priority: "high",
handlers: [
{
route: "/(.*)",
handler: "cache",
options: {
cacheKey: "astro-cache",
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365,
staleWhileRevalidateSeconds: 60 * 60 * 24 * 365,
},
browser: {
maxAgeSeconds: 60 * 60 * 24 * 365,
serviceWorkerSeconds: 60 * 60 * 24 * 365,
},
},
},
],
},
})
: node({
mode: "standalone",
}),
site: seoConfig.baseURL,
compressHTML: true,
integrations: [
react(),
prefetch({
// Prefetch all pages in the /blog directory
include: ["/**"],
}),
sitemap(),
Compress({
CSS: true,
HTML: true,
Image: true,
JavaScript: true,
SVG: true,
}),
],
build: {
inlineStylesheets: "auto",
},
vite: {
build: {
chunkSizeWarningLimit: 10000000,
},
plugins: [
VitePWA({
registerType: "autoUpdate",
disable: isDev,
manifest,
workbox: {
globDirectory: isDocker ? "./dist/client" : "./.vercel/output/static",
globPatterns: [
"**/*.{js,css,svg,png,jpg,jpeg,gif,webp,woff,woff2,ttf,eot,ico}",
],
// Don't fallback on document based (e.g. `/some-page`) requests
// This removes an errant console.log message from showing up.
navigateFallback: null,
inlineWorkboxRuntime: true,
cleanupOutdatedCaches: true,
runtimeCaching: [
{
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp)$/,
handler: "CacheFirst",
options: {
cacheName: "images",
expiration: {
maxEntries: 20,
// 30 days
maxAgeSeconds: 30 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
// Only cache 10 images.
maxEntries: 10,
// Cache for a maximum of a week.
maxAgeSeconds: 7 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
},
},
},
{
urlPattern: /\.(?:js|css)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "static-resources",
expiration: {
maxEntries: 20,
// 30 days
maxAgeSeconds: 30 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
// Only cache 10 images.
maxEntries: 10,
// Cache for a maximum of a week.
maxAgeSeconds: 7 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
},
},
},
{
urlPattern: /\.(?:woff|woff2|ttf|eot|ico)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "fonts",
expiration: {
maxEntries: 20,
// 30 days
maxAgeSeconds: 30 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
// Only cache 10 images.
maxEntries: 10,
// Cache for a maximum of a week.
maxAgeSeconds: 7 * 24 * 60 * 60,
// Automatically cleanup if quota is exceeded.
purgeOnQuotaError: true,
},
},
},
],
},
}),
],
},
});