-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvite.config.ts
154 lines (141 loc) · 4.19 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { defineConfig } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
import path from "path";
import react from "@vitejs/plugin-react";
import { terser } from 'rollup-plugin-terser';
import { meteorPath } from "meteorproxy"
import postcss from 'postcss';
const __dirname = path.resolve();
function isErrorWithCause(log: any): log is { cause: { message: string } } {
return log.cause && typeof (log.cause as { message: string }).message === 'string';
}
export default defineConfig({
plugins: [
//we're using the direct paths instead of the exported uvPath epoxyPath etc because typescript support for some is weird
viteStaticCopy({
targets: [
{
src: `node_modules/@titaniumnetwork-dev/ultraviolet/dist/**/*`.replace(/\\/g, "/"),
dest: "&",
overwrite: false
},
{
src: `node_modules/@mercuryworkshop/epoxy-transport/dist/**/*`.replace(/\\/g, "/"),
dest: "epoxy",
overwrite: false
},
{
src: `node_modules/meteorproxy/dist/meteor.*`.replace(/\\/g, "/"),
dest: "!",
overwrite: false,
},
{
src: `node_modules/@mercuryworkshop/libcurl-transport/dist/**/*`.replace(/\\/g, "/"),
dest: "libcurl",
overwrite: false
},
{
src: `node_modules/@mercuryworkshop/bare-mux/dist/*.js.*`.replace(/\\/g, '/'),
dest: 'baremux',
overwrite: false
},
{
src: `node_modules/@mercuryworkshop/bare-mux/dist/*.js`.replace(/\\/g, "/"),
dest: 'baremux',
overwrite: false
},
//for that one index.mjs lmao
{
src: `node_modules/@mercuryworkshop/bare-mux/dist/*.mjs`.replace(/\\/g, "/"),
dest: "baremux",
overwrite: false
}
]
}),
,
react(),
terser({
compress: {
drop_debugger: true,
},
output: {
comments: false,
},
}),
{
name: 'add-defer-to-links',
enforce: 'post',
transformIndexHtml(html: string) {
return html.replace(
/<link (.*?)>/g,
(match: any, attributes: string | string[]) => {
if (!attributes.includes('defer') && !attributes.includes('rel="preload"') && !attributes.includes('rel="prefetch"')) {
return `<link ${attributes} defer>`;
}
return match;
},
);
},
} as unknown as Plugin,
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
}
},
server: {
host: "0.0.0.0",
port: 8080,
watch: {
usePolling: true
},
proxy: {
"/bare/": {
target: "http://localhost:8080/bare/",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/bare\//, "")
},
"/wisp/": {
target: "http://localhost:8080/wisp/",
changeOrigin: true,
ws: true,
rewrite: (path) => path.replace(/^\/wisp\//, "")
},
}
},
build: {
sourcemap: true,
assetsInlineLimit: 8192,
cssCodeSplit: true,
minify: terser,
rollupOptions: {
output: {
entryFileNames: assetInfo => {
if (assetInfo.name && assetInfo.name.includes('index')) {
return 'assets/js/index.js';
}
if (assetInfo.name && assetInfo.name.includes('lucide')) {
return `assets/icons/lucide${path.extname(assetInfo.name)}`;
}
return 'assets/js/[name].[hash].js';
},
chunkFileNames: 'assets/js/[name].[hash].js',
assetFileNames: assetInfo => {
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
return 'assets/css/index.css';
}
if (assetInfo.name && assetInfo.name.includes('lucide')) {
return `assets/icons/lucide${path.extname(assetInfo.name)}`;
}
return 'assets/[name].[hash][extname]';
},
},
onLog(level, log, handler) {
if (isErrorWithCause(log) && log.cause.message === `Can't resolve original location of error.`) {
return;
}
handler(level, log);
},
}
},
});