-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathvite.config.ts
64 lines (58 loc) · 1.54 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
import {
getReplicaHost,
readCanisterId,
} from "@dfinity/internet-identity-vite-plugins";
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
const rewriteRoute = (pathAndParams: string): string => {
let queryParamsString = `?`;
const [path, params] = pathAndParams.split("?");
if (params) {
queryParamsString += `${params}&`;
}
queryParamsString += `canisterId=${readCanisterId({
canisterName: "test_app",
})}`;
return path + queryParamsString;
};
export default defineConfig(({ command, mode }) => ({
root: "./src",
build: {
outDir: "../dist",
emptyOutDir: true,
rollupOptions: {
output: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`,
},
},
},
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
},
},
plugins: [nodePolyfills({ include: ["buffer"] })],
server:
command !== "serve"
? undefined
: {
port: 8081,
// Set up a proxy that redirects API calls and /index.html to the
// replica; the rest we serve from here.
proxy: {
"/api": getReplicaHost(),
"/.well-known/ii-alternative-origins": {
target: getReplicaHost(),
rewrite: rewriteRoute,
},
"/.well-known/evil-alternative-origins": {
target: getReplicaHost(),
rewrite: rewriteRoute,
},
},
},
}));