-
Notifications
You must be signed in to change notification settings - Fork 19
/
vite.config.js
77 lines (69 loc) · 1.77 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
74
75
76
77
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import dfxJson from "./dfx.json";
import WindiCSS from 'vite-plugin-windicss'
let localCanisters, prodCanisters, canisters;
function initCanisterIds() {
try {
localCanisters = require(path.resolve(
".dfx",
"local",
"canister_ids.json"
));
} catch (error) {
console.log("No local canister_ids.json found. Continuing production");
}
try {
prodCanisters = require(path.resolve("canister_ids.json"));
} catch (error) {
console.log("No production canister_ids.json found. Continuing with local");
}
const network = process.env.DFX_NETWORK || "local";
canisters = network === "local" ? localCanisters : prodCanisters;
for (const canister in canisters) {
process.env["VITE_APP_" + canister.toUpperCase() + "_CANISTER_ID"] =
canisters[canister][network];
}
}
initCanisterIds();
// List of all aliases for canisters
const aliases = Object.entries(dfxJson.canisters).reduce(
(acc, [name, _value]) => {
// Get the network name, or `local` by default.
const networkName = process.env["DFX_NETWORK"] || "local";
const outputRoot = path.join(
__dirname,
".dfx",
networkName,
"canisters",
name
);
return {
...acc,
["dfx-generated/" + name]: path.join(outputRoot, name + ".did.js"),
};
},
{}
);
//https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), WindiCSS()],
resolve: {
alias: {
...aliases,
},
},
define: {
"process.env": process.env,
},
server: {
proxy: {
"/api": {
target: "http://localhost:8000",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, "/api"),
},
},
},
});