Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
80 lines (71 loc) · 2 KB
/
Copy pathvite.config.ts
File metadata and controls
80 lines (71 loc) · 2 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
import { configDefaults, defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import type { Plugin } from "vite";
function inlineCss(): Plugin {
return {
name: "inline-css",
enforce: "post",
generateBundle(_options, bundle) {
const stylesheetLink =
/<link\b(?=[^>]*\brel=["']stylesheet["'])(?=[^>]*\bhref=["']([^"']+)["'])[^>]*>/gi;
const inlinedCss = new Set<string>();
for (const output of Object.values(bundle)) {
if (output.type !== "asset" || !output.fileName.endsWith(".html")) {
continue;
}
const html = String(output.source).replace(
stylesheetLink,
(link, href: string) => {
const fileName = new URL(href, "https://vite.invalid/").pathname
.replace(/^\//, "");
const stylesheet = bundle[fileName];
if (
stylesheet?.type !== "asset" ||
!stylesheet.fileName.endsWith(".css")
) {
return link;
}
inlinedCss.add(fileName);
const css = String(stylesheet.source).replace(
/<\/style/gi,
"<\\/style",
);
return `<style data-croc-inline-css>${css}</style>`;
},
);
output.source = html;
}
for (const fileName of inlinedCss) {
delete bundle[fileName];
}
},
};
}
const gatewayProxy =
process.env.CROC_GATEWAY_PROXY ?? "ws://127.0.0.1:9014";
export default defineConfig({
plugins: [react(), inlineCss()],
server: {
fs: {
allow: [".."],
},
host: "127.0.0.1",
proxy: {
"/ws": {
target: gatewayProxy,
ws: true,
},
"/healthz": {
target: gatewayProxy.replace(/^ws/, "http"),
},
"/api": {
target: gatewayProxy.replace(/^ws/, "http"),
},
},
},
test: {
environment: "jsdom",
setupFiles: ["./src/test/setup.ts"],
exclude: [...configDefaults.exclude, "e2e/**"],
},
});