Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
122 lines (118 loc) · 3.29 KB
/
Copy pathvite.config.js
File metadata and controls
122 lines (118 loc) · 3.29 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
113
114
115
116
117
118
119
120
121
122
import { defineConfig } from "vite";
import istanbul from "vite-plugin-istanbul";
import { readFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
const coverageEnabled = process.env.PW_COVERAGE === "1";
const port = Number(process.env.PORT || 4000);
const apiPort = process.env.PW_API_PORT || "3000";
const apiUrl = `http://localhost:${apiPort}/`;
const jasmineCore = createRequire(import.meta.url)("jasmine-core");
const jasmineAssets = new Set([
...jasmineCore.files.bootFiles,
...jasmineCore.files.cssFiles,
...jasmineCore.files.jsFiles,
]);
const sourcePackageAliases = [
{
find: /^@angular-wave\/angular\.ts\/services\/wasm$/,
replacement: fileURLToPath(
new URL("../src/services/wasm/index.ts", import.meta.url),
),
},
{
find: /^@angular-wave\/angular\.ts\/runtime\/wasm$/,
replacement: fileURLToPath(
new URL("../src/runtime/wasm.ts", import.meta.url),
),
},
{
find: /^@angular-wave\/angular\.ts$/,
replacement: fileURLToPath(new URL("../src/index.ts", import.meta.url)),
},
];
const wasmWorkerIsolation = {
name: "wasm-worker-isolation",
configureServer(server) {
server.middlewares.use((request, response, next) => {
if (request.url?.startsWith("/concepts/wasm-worker")) {
response.setHeader("Cross-Origin-Opener-Policy", "same-origin");
response.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
}
next();
});
},
};
const jasmineCoreAssets = {
name: "jasmine-core-assets",
configureServer(server) {
server.middlewares.use(async (request, response, next) => {
const match = request.url?.match(/^\/jasmine\/([^/?]+)(?:[?#].*)?$/);
const asset = match?.[1];
if (!asset || !jasmineAssets.has(asset)) {
next();
return;
}
try {
response.setHeader(
"Content-Type",
asset.endsWith(".css") ? "text/css" : "text/javascript",
);
response.end(await readFile(`${jasmineCore.files.path}/${asset}`));
} catch (error) {
next(error);
}
});
},
};
export default defineConfig({
define: {
__PW_API_URL__: JSON.stringify(apiUrl),
},
resolve: {
alias: sourcePackageAliases,
},
plugins: [
...(coverageEnabled
? [
istanbul({
include: ["src/**/*.js", "src/**/*.ts"],
exclude: ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.html"],
extension: [".js", ".ts"],
requireEnv: false,
checkProd: false,
}),
]
: []),
wasmWorkerIsolation,
jasmineCoreAssets,
],
server: {
port,
strictPort: true,
watch: {
// Test and integration servers share the OS watcher limit with editors and build tools.
usePolling: true,
interval: 1000,
ignored: [
"**/.coverage/**",
"**/coverage/**",
"**/concepts/unity-fps/unity-project/Library/**",
"**/docs/**",
"**/integrations/**",
"**/tools/vscode/.vscode-test/**",
],
},
proxy: {
"/api": {
target: apiUrl,
changeOrigin: true,
},
"/mock": {
target: apiUrl,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/mock/, ""),
},
},
},
});