Repository navigation
Expand file tree
/
Copy pathastro.config.mjs
More file actions
108 lines (102 loc) · 3.12 KB
/
Copy pathastro.config.mjs
File metadata and controls
108 lines (102 loc) · 3.12 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
// @ts-check
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'astro/config';
import { build as viteBuild } from 'vite';
import { injectManifest } from 'workbox-build';
import react from '@astrojs/react';
import tailwindcss from '@tailwindcss/vite';
import { VitePWA } from 'vite-plugin-pwa';
const isGitHub = !!process.env.GITHUB_ACTIONS;
const sourceRoot = fileURLToPath(new URL('./src', import.meta.url));
// This project deploys through Cloudflare Workers.
const adapter = (await import('@astrojs/cloudflare')).default();
// GitHub Pages deploys under /bytekit/ subpath; others serve from root
const base = isGitHub ? '/bytekit' : '/';
const pwaBase = `${base}/`.replace(/\/+/g, '/');
const offlineServiceWorker = {
name: 'bytekit-offline-service-worker',
hooks: {
'astro:build:done': async ({ dir }) => {
const outDir = fileURLToPath(dir);
const swPath = resolve(outDir, 'sw.js');
await viteBuild({
configFile: false,
base: pwaBase,
define: { 'process.env.NODE_ENV': '"production"' },
build: {
outDir,
emptyOutDir: false,
lib: { entry: resolve('src/sw.ts'), formats: ['iife'], name: 'BytekitServiceWorker', fileName: () => 'sw.js' },
},
});
await injectManifest({
swSrc: swPath,
swDest: swPath,
globDirectory: outDir,
globPatterns: ['**/*.{css,html,ico,js,json,mjs,png,svg,webmanifest,woff,woff2,wasm}'],
globIgnores: ['sw.js'],
maximumFileSizeToCacheInBytes: 6 * 1024 * 1024,
});
},
},
};
// https://astro.build/config
export default defineConfig({
output: 'static',
base,
integrations: [react(), offlineServiceWorker],
adapter,
vite: {
plugins: [
tailwindcss(),
VitePWA({
strategies: 'injectManifest',
srcDir: 'src',
outDir: 'dist/client',
filename: 'sw.ts',
injectRegister: false,
registerType: 'prompt',
base: pwaBase,
manifest: {
name: 'Bytekit 开发工具站',
short_name: 'Bytekit',
description: '本地优先的开发工具站',
id: pwaBase,
start_url: pwaBase,
scope: pwaBase,
display: 'standalone',
background_color: '#ffffff',
theme_color: '#ffffff',
icons: [{ src: 'favicon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any maskable' }],
},
injectManifest: {
maximumFileSizeToCacheInBytes: 6 * 1024 * 1024,
},
devOptions: { enabled: false },
}),
],
resolve: {
dedupe: ['react', 'react-dom'],
alias: {
'@app': fileURLToPath(new URL('./src/app', import.meta.url)),
'@features': fileURLToPath(new URL('./src/features', import.meta.url)),
'@shared': fileURLToPath(new URL('./src/shared', import.meta.url)),
'@themes': fileURLToPath(new URL('./src/themes', import.meta.url)),
'@': sourceRoot,
},
},
optimizeDeps: {
include: [
'@radix-ui/react-toast',
'astro/virtual-modules/transitions-events.js',
'astro/virtual-modules/transitions-router.js',
'astro/virtual-modules/transitions-swap-functions.js',
'astro/virtual-modules/transitions-types.js',
'astro/virtual-modules/transitions.js',
'lucide-react',
'minisearch',
],
},
},
});