-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
122 lines (113 loc) · 2.97 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
import path from 'path';
import { vite } from '@darkobits/tsx';
import { faviconsPlugin } from '@darkobits/vite-plugin-favicons';
import tailwindCssPlugin from '@tailwindcss/vite';
// import devcert from 'devcert';
import { visualizer } from 'rollup-plugin-visualizer';
import { VitePWA } from 'vite-plugin-pwa';
/**
* N.B. This _must_ match infra/WebStack.ts.
*/
const WEB_PATH = path.join('src', 'web');
export default vite.react(({ config, packageJson, root, ms, manualChunks }) => {
config.root= WEB_PATH;
manualChunks([{
name: 'react',
vendor: true,
include: [
'@restart/',
'object-assign/',
'react-bootstrap',
'react-dom',
'react',
'scheduler',
'use-async-effect'
]
}, {
name: 'chance',
vendor: true,
include: [
'chance'
]
}, {
name: 'storage',
vendor: true,
include: [
'localforage'
]
}, {
name: 'vendor',
include: [
'node_modules',
'~icons'
]
}]);
config.plugins.push(tailwindCssPlugin());
config.plugins.push(faviconsPlugin({
appName: 'Inspirat',
appDescription: packageJson.description,
version: packageJson.version,
developerName: packageJson.author?.name as string,
developerURL: packageJson.homepage as string,
icons: {
favicons: {
source: path.resolve(root, 'assets', 'favicon.png')
}
}
}));
// PWA support.
config.plugins.push(VitePWA({
// TODO: Fix this typing in tsx.
outDir: config.build.outDir as string,
filename: 'service-worker.js',
manifest: {
name: 'Inspirat',
description: packageJson.description,
display: 'standalone',
background_color: '#000',
theme_color: '#000'
},
injectRegister: null,
workbox: {
globPatterns: [
'**'
],
globIgnores: [
'**/node_modules/**/*',
'**/apple-touch-*',
'**/android-chrome-*',
'**/firefox_app_*',
'**/favicon-*'
],
cacheId: packageJson.name,
runtimeCaching: [{
// The StaleWhileRevalidate strategy tells Workbox to serve the cached
// asset while it tries to fetch a newer version.
handler: 'StaleWhileRevalidate',
urlPattern: new RegExp(`(${[
// To allow Workbox to cache requests from Google Fonts, we must use a
// pattern that matches the start of the URL.
'^https://fonts.googleapis.com',
// Match any other requests.
'.*'
].join('|')})`, 'g'),
options: {
// If a network request fails, allow Workbox to replay the request
// when connectivity has been restored.
backgroundSync: {
name: 'background-sync-queue',
options: {
maxRetentionTime: ms('20 seconds')
}
}
}
}]
}
}));
config.plugins.push(visualizer({
emitFile: true,
filename: 'build-stats.html',
template: 'sunburst',
gzipSize: true
}));
});