-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
73 lines (72 loc) · 1.91 KB
/
vite.config.js
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
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { sync as glob } from "glob";
import { resolve } from "path";
// https://vitejs.dev/config/
export default defineConfig({
appType: "mpa",
plugins: [
nodePolyfills({
include: ["crypto", "stream", "util", "buffer"],
}),
{
name: "build-tree",
enforce: "post",
generateBundle(_, bundle) {
const isSrc = /^src\/.*\.html$/;
for (const out of Object.values(bundle)) {
if (isSrc.test(out.fileName))
out.fileName = out.fileName.replace("src/client/pages/", "");
}
},
},
{
name: "dev-tree",
configureServer(server) {
server.middlewares.use((req, _, next) => {
const redirect = /(?<!src[\w\/]*)((\/\w+\/$)|(\/\w+.js$))/;
if (redirect.test(req.url)) req.url = `/src/client/pages${req.url}`;
next();
});
},
resolveId(id) {
const redirect = /(?<!src[\w\/]*)(\/\w+.js$)/;
return redirect.test(id)
? resolve(__dirname, `./src/client/pages/${id}`)
: null;
},
},
],
resolve: {
alias: [
{ find: "@", replacement: resolve(__dirname, "./src") },
{ find: "~", replacement: resolve(__dirname, "./src/client") },
{ find: "#", replacement: resolve(__dirname, "./src/client/pages") },
],
},
server: {
strictPort: true,
},
build: {
rollupOptions: {
input: ["./index.html", ...glob("./src/client/**/*.html")],
output: {
dir: "dist",
format: "esm",
manualChunks: {
axios: ["axios"],
pdf: ["pdf-lib"],
utils: ["stream", "util", "buffer", "randombytes"],
crypto: ["crypto"],
},
},
},
minify: "terser",
terserOptions: {
compress: {
arguments: true,
drop_debugger: true,
},
},
},
});