-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
82 lines (78 loc) · 1.99 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
import { extname } from "path";
import react from "@vitejs/plugin-react-swc";
import autoprefixer from "autoprefixer";
import { csvParse, tsvParse } from "d3-dsv";
import postCSSNesting from "postcss-nesting";
import tailwindcss from "tailwindcss";
import tailwindcssNesting from "tailwindcss/nesting";
import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
import { ViteMinifyPlugin } from "vite-plugin-minify";
import { VitePWA } from "vite-plugin-pwa";
import type { UserConfig } from "vite";
const dsvParsers: Record<string, ((input: string) => unknown) | undefined> = { ".csv": csvParse, ".tsv": tsvParse };
export default {
base: "./",
plugins: [
react(),
{
name: "dsv-transform",
transform(code, id) {
const parser = dsvParsers[extname(id)];
return parser && {
code: `export default JSON.parse(${JSON.stringify(JSON.stringify(parser(code)))});`,
map: { mappings: "" },
};
},
},
ViteMinifyPlugin(),
ViteImageOptimizer(),
VitePWA({
outDir: "build",
registerType: "autoUpdate",
manifest: false,
includeAssets: [
"./assets/favicon-64x64.png",
"./assets/favicon-128x128.png",
"./assets/favicon-192x192.png",
"./assets/hkilang-logo.svg",
"./assets/credit-logos.svg",
],
workbox: {
runtimeCaching: [
{
urlPattern: ({ url }) => url.origin === "https://cdn.jsdelivr.net",
handler: "CacheFirst",
options: {
cacheName: "jsdelivr-cache",
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
maximumFileSizeToCacheInBytes: 4194304,
},
}),
],
css: {
postcss: {
plugins: [
tailwindcssNesting(postCSSNesting({ edition: "2024-02" })),
tailwindcss(),
autoprefixer(),
],
},
},
build: {
outDir: "build",
target: "ES2017",
rollupOptions: {
output: {
assetFileNames: "[name].[hash].[ext]",
chunkFileNames: "[name].[hash].js",
entryFileNames: "[name].[hash].js",
hashCharacters: "hex",
},
},
},
} satisfies UserConfig;