-
Notifications
You must be signed in to change notification settings - Fork 11.5k
/
vite.config.ts
124 lines (121 loc) · 3.03 KB
/
vite.config.ts
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
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import pkg from './package.json';
import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa';
const { name, version, dependencies, devDependencies } = pkg;
const __APP_INFO__ = {
buildTimestamp: Date.now(),
name,
version,
dependencies,
devDependencies,
};
const initPwaOptions = (env: Record<string, string>) => {
const pwaOptions: Partial<VitePWAOptions> = {
// srcDir: 'src',
// filename: 'sw.ts',
includeAssets: ['img/logo.svg'],
manifest: {
name: 'BingAI',
short_name: 'BingAI',
theme_color: '#ffffff',
icons: [
{
src: './img/pwa/logo-192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: './img/pwa/logo-512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: './img/pwa/logo-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
// devOptions: {
// enabled: true,
// type: 'module',
// },
// strategies: 'injectManifest',
// workbox: {
// cleanupOutdatedCaches: true,
// clientsClaim: true,
// skipWaiting: true,
// },
// 取消注册服务工作进程
// selfDestroying: true,
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
runtimeCaching: [
{
urlPattern: /(.*?)\.(js|css|ts)/, // js /css /ts静态资源缓存
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'BingAI-assets',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 7,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps|ico)/, // 图片缓存
handler: 'CacheFirst',
options: {
cacheName: 'BingAI-images',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 7,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
};
return pwaOptions;
};
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
base: '/web',
server: {
port: 4000,
open: false,
host: '0.0.0.0',
proxy: {
'^/(?!web)': {
ws: true,
target: env.VITE_BASE_API_URL,
changeOrigin: true,
},
},
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
plugins: [vue(), VitePWA(initPwaOptions(env))],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
outDir: '../web',
},
};
});