-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
vite.config.ts
88 lines (78 loc) · 2.21 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
import { defineConfig } from 'vitest/config';
import { join, resolve } from 'path';
import { copy } from 'fs-extra';
import { generateSW } from 'workbox-build';
import { config } from './scripts/vite.config.mjs';
import { __DEV__ } from './scripts/utils.mjs';
const r = (...path) => resolve(__dirname, ...path);
const hashRegExp = /-[0-9a-fA-F]{8}\./;
export default defineConfig(() => {
const outDir = r('dist', 'public');
const input = [
r('src', 'index.html'),
r('src', 'sandbox.html'),
__DEV__ && r('src', 'embed.html'),
].filter(Boolean);
return {
...config,
root: r('src'),
publicDir: r('public'),
server: {
open: __DEV__,
proxy: {
'/api': {
target: 'http://localhost:8888/.netlify/functions',
changeOrigin: true,
rewrite: (p) => p.replace(/^\/api/, '').replace(/\.js$/, ''),
},
'^gist/.*': 'http://localhost:5173',
},
},
build: {
outDir,
emptyOutDir: true,
rollupOptions: {
input,
output: {
entryFileNames: '[name].js',
},
},
},
plugins: [
...config.plugins,
{
name: 'post-build',
async generateBundle() {
await Promise.all([
copy('_redirects', join(outDir, '_redirects')),
copy('.well-known', join(outDir, '.well-known')),
]);
await generateSW({
globDirectory: 'dist/public',
globPatterns: ['**/*.{html,js,css,png,svg,jpg,gif,json,ico}'],
swDest: r('dist/public/sw.js'),
clientsClaim: true,
skipWaiting: true,
manifestTransforms: [
async function removeRevisionManifestTransform(manifestEntries) {
return {
manifest: manifestEntries.map((entry) =>
hashRegExp.test(entry.url)
? { ...entry, revision: null }
: entry,
),
};
},
],
ignoreURLParametersMatching: [/.*/],
});
},
},
],
test: {
globals: true,
environment: 'jsdom',
setupFiles: '../tests/setupTests',
},
};
});