-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathvite.config.ts
More file actions
112 lines (109 loc) · 3.39 KB
/
Copy pathvite.config.ts
File metadata and controls
112 lines (109 loc) · 3.39 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
109
110
111
112
import react from "@vitejs/plugin-react-swc";
import { promises as fs } from "fs";
import { resolve } from "path";
import { defineConfig } from "vite";
// import mkcert from "vite-plugin-mkcert";
import { VitePWA } from "vite-plugin-pwa";
import { viteStaticCopy } from "vite-plugin-static-copy";
const backend = "http://localhost:5212";
const backendProxyOption = { target: backend, headers: { host: new URL(backend).host } };
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: "prompt",
injectRegister: "auto",
manifest: false,
workbox: {
globIgnores: ["**/*leaflet*", "**/*mapbox*", "**/*Leaflet*", "**/*Mapbox*"],
maximumFileSizeToCacheInBytes: 10000000,
navigateFallbackDenylist: [/^\/pdfviewer.html/, /^\/api\/(.+)/, /^\/f\/(.+)/, /^\/s\/(.+)/],
},
devOptions: {
enabled: true,
},
}),
viteStaticCopy({
targets: [
{
src: "node_modules/pdfjs-dist/build/*.mjs",
dest: "assets/pdfjs",
},
],
}),
{
name: "load-stylesheet-async",
transformIndexHtml(html) {
return html.replace(
/<link rel="stylesheet" crossorigin href="(.+?)">/g,
`<link rel="stylesheet" crossorigin href="$1" media="print" onload="this.media='all'">`,
);
},
},
{
name: "generate-version",
async writeBundle(outputOptions) {
const version = {
name: process.env.npm_package_name,
version: process.env.npm_package_version,
};
const path = resolve(__dirname, outputOptions.dir, "version.json");
await fs.writeFile(path, JSON.stringify(version));
},
},
// mkcert({
// hosts: ["devv5.cloudreve.org"],
// }),
],
define: {
__ASSETS_VERSION__: JSON.stringify(process.env.npm_package_version),
},
build: {
outDir: "build", // keep same as v3 with minimal changes
rollupOptions: {
output: {
manualChunks: (id) => {
const chunkMap = {
common: [
"vite/preload-helper",
"vite/modulepreload-polyfill",
"vite/dynamic-import-helper",
"commonjsHelpers",
"commonjs-dynamic-modules",
"__vite-browser-external",
],
monaco: ["monaco-editor"],
codemirror: ["@codemirror"],
excalidraw: [
"node_modules/@excalidraw",
"node_modules/browser-fs-access",
"node_modules/image-blob-reduce",
"node_modules/pica/",
],
mermaid: ["node_modules/mermaid", "node_modules/katex"],
leaflet: ["node_modules/leaflet", "node_modules/react-leaflet"],
react: ["node_modules/react", "node_modules/react-dom"],
mapbox: ["node_modules/mapbox-gl"],
};
// https://github.com/vitejs/vite/issues/5189#issuecomment-2175410148
for (const [chunkName, patterns] of Object.entries(chunkMap)) {
if (patterns.some((pattern) => id.includes(pattern))) {
return chunkName;
}
}
},
},
},
},
server: {
host: "0.0.0.0",
cors: false,
proxy: {
"/api": backendProxyOption,
"/s/": backendProxyOption,
"/f/": backendProxyOption,
"/manifest.json": backendProxyOption,
},
},
});