-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvite.config.ts
180 lines (170 loc) · 4.58 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { defineConfig } from "vite";
import path from "path";
import dfxJson from "./dfx.json";
import fs from "fs";
import { VitePWA } from "vite-plugin-pwa";
const isDev = process.env["DFX_NETWORK"] === "local";
// Get the network name, or `local` by default.
const networkName = process.env["DFX_NETWORK"] || "local";
type Network = "ic" | "development" | "testing" | "local";
interface CanisterIds {
[key: string]: { [key in Network]: string };
}
let canisterIds: CanisterIds = {};
try {
canisterIds = JSON.parse(
fs
.readFileSync(
isDev ? ".dfx/local/canister_ids.json" : "./canister_ids.json",
)
.toString(),
);
} catch (e) {
console.error("\n⚠️ Before starting the dev server run: dfx deploy\n\n");
}
// List of all aliases for canisters
// This will allow us to: import { canisterName } from "canisters/canisterName"
const aliases = Object.entries(dfxJson.canisters || {}).reduce(
(acc, [name, _value]) => {
/* const outputRoot = path.join(
__dirname,
".dfx",
networkName,
"canisters",
name,
); */
const outputRoot = path.join(
__dirname,
"src",
"declarations",
name,
);
return {
...acc,
["canisters/" + name]: path.join(outputRoot, "index" + ".js"),
};
},
{},
);
// Generate canister ids, required by the generated canister code in .dfx/local/canisters/*
// This strange way of JSON.stringifying the value is required by vite
const canisterDefinitions = Object.entries(canisterIds).reduce(
(acc, [key, val]) => ({
...acc,
[`process.env.${key.toUpperCase()}_CANISTER_ID`]: JSON.stringify(val[networkName]),
[`process.env.CANISTER_ID_${key.toUpperCase()}`]: JSON.stringify(val[networkName]),
}),
{},
);
const pwaManifest = {
short_name: "DeVinci",
name: "DeVinci AI Chat App",
description: "Your decentralized AI Chat app served from the Internet Computer and running on your device through the browser.",
display: "standalone",
scope: "/",
start_url: "/",
background_color: "#b0c4de",
theme_color: "#b0c4de",
lang: "en",
dir: "ltr",
orientation: "any",
categories: ["productivity", "ai", "chatbot"],
icons: [
{
src: './devinci192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: './devinci512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
},
{
src: "./devinci1024.png",
type: "image/png",
sizes: "1024x1024"
},
],
screenshots: [
{
src: "./meta.jpg",
type: "image/jpg",
sizes: "1600x840"
},
],
shortcuts: [
{
name: "Start New Chat",
short_name: "New Chat",
description: "Start a new AI chat session",
url: "/",
icons: [{ src: "./devinci192.png", sizes: "192x192" }]
}
]
};
const pwaOptions = {
registerType: 'autoUpdate',
manifest: pwaManifest,
injectRegister: null,
// for own service worker (not auto-generated)
strategies: 'injectManifest',
srcDir: 'src/DeVinci_frontend',
filename: 'service-worker.ts',
outDir: './dist/',
injectManifest: {
//injectionPoint: undefined
rollupFormat: 'iife',
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,gif}'],
maximumFileSizeToCacheInBytes: 50000000, // Increase or decrease based on your needs
},
devOptions: {
enabled: true
}
};
// See guide on how to configure Vite at:
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte(),
VitePWA(pwaOptions)
],
build: {
target: "es2020",
},
resolve: {
alias: {
// Here we tell Vite the "fake" modules that we want to define
...aliases,
},
},
//publicDir: "./src/DeVinci_frontend/public",
publicDir: "./src/DeVinci_frontend/assets",
server: {
host: true,
fs: {
allow: ["."],
},
//__________Local vs Mainnet Development____________
proxy: {
// This proxies all http requests made to /api to our running dfx instance
"/api": {
target: `http://127.0.0.1:4943`,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, "/api"),
},
},
},
define: {
// Here we can define global constants
// This is required for now because the code generated by dfx relies on process.env being set
...canisterDefinitions,
"process.env.NODE_ENV": JSON.stringify(
isDev ? "development" : "production",
),
"process.env.DFX_NETWORK": JSON.stringify(process.env["DFX_NETWORK"]),
global: process.env.NODE_ENV === "development" ? "globalThis" : "global",
},
});