-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvite.config.ts
More file actions
261 lines (246 loc) · 11.6 KB
/
vite.config.ts
File metadata and controls
261 lines (246 loc) · 11.6 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import path from "path";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig, loadEnv } from "vite";
import electron from "vite-plugin-electron/simple";
export default defineConfig(({ mode }) => {
const isProd = mode === "production";
// Enable source maps in development mode only
const enableSourceMap = !isProd;
// Load environment variables from .env file
const env = loadEnv(mode, process.cwd(), "");
// Debug: Log if Supabase credentials are loaded
const supabaseUrl = env.SUPABASE_URL || process.env.SUPABASE_URL || "";
const supabaseKey = env.SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY || "";
const azureBlobBaseUrl = env.AZURE_BLOB_BASE_URL || process.env.AZURE_BLOB_BASE_URL || "";
const updatesOrigin = env.PPTB_UPDATES_ORIGIN || process.env.PPTB_UPDATES_ORIGIN || "https://www.powerplatformtoolbox.com";
if (supabaseUrl && supabaseKey) {
console.log("[Vite] Supabase credentials loaded successfully");
} else {
console.warn("[Vite] WARNING: Supabase credentials not found in environment");
console.warn("[Vite] Make sure .env file exists with SUPABASE_URL and SUPABASE_ANON_KEY");
}
if (azureBlobBaseUrl) {
console.log("[Vite] Azure Blob base URL loaded successfully");
} else {
console.warn("[Vite] WARNING: AZURE_BLOB_BASE_URL not set - Azure Blob registry fallback will be disabled");
}
// Define environment variables for the build
// These will be replaced at build time, not exposed in the bundle
const envDefines = {
"process.env.SUPABASE_URL": JSON.stringify(supabaseUrl),
"process.env.SUPABASE_ANON_KEY": JSON.stringify(supabaseKey),
"process.env.AZURE_BLOB_BASE_URL": JSON.stringify(azureBlobBaseUrl),
"process.env.PPTB_UPDATES_ORIGIN": JSON.stringify(updatesOrigin),
};
return {
plugins: [
electron({
main: {
// Main process entry point
entry: "src/main/index.ts",
vite: {
define: envDefines,
build: {
// Only include source maps when not building for production
sourcemap: enableSourceMap,
outDir: "dist/main",
rollupOptions: {
output: {
entryFileNames: "index.js",
},
},
},
plugins: [
// Bundle analysis for main process
visualizer({
filename: "dist/stats-main.html",
open: false,
gzipSize: true,
brotliSize: true,
}),
],
},
},
preload: {
// Preload scripts - build both main window preload and tool preload
input: {
preload: "src/main/preload.ts",
toolPreloadBridge: "src/main/toolPreloadBridge.ts",
notificationPreload: "src/main/notificationPreload.ts",
modalPreload: "src/main/modalPreload.ts",
},
vite: {
build: {
// Only include source maps when not building for production
sourcemap: enableSourceMap,
outDir: "dist/main",
rollupOptions: {
output: {
entryFileNames: "[name].js",
inlineDynamicImports: false,
},
},
},
},
},
// Polyfill node built-in modules for renderer process
renderer: {},
}),
// // Fail builds immediately if the renderer TypeScript project has errors
// checker({
// typescript: {
// tsconfigPath: "tsconfig.renderer.json",
// buildMode: true,
// },
// }),
// Plugin to inject the configured PPTB_UPDATES_ORIGIN into the CSP meta tag at build time
{
name: "inject-csp-updates-origin",
transformIndexHtml(html: string) {
return html.replace(/__PPTB_UPDATES_ORIGIN__/g, updatesOrigin);
},
},
// Custom plugin to reorganize output and copy static assets
{
name: "reorganize-output",
closeBundle() {
// Move HTML from nested path to root of dist/renderer and fix paths
const nestedHtml = "dist/renderer/src/renderer/index.html";
const targetHtml = "dist/renderer/index.html";
if (existsSync(nestedHtml)) {
// Read the HTML content
let htmlContent = readFileSync(nestedHtml, "utf-8");
// Fix asset paths from ../../assets/ to ./assets/
htmlContent = htmlContent.replace(/\.\.\/\.\.\/assets\//g, "./assets/");
// Write to target location
writeFileSync(targetHtml, htmlContent);
// Clean up nested directory structure
try {
rmSync("dist/renderer/src", { recursive: true, force: true });
} catch (e) {
// Ignore cleanup errors
}
}
// Create icons directory if it doesn't exist
try {
mkdirSync("dist/renderer/icons", { recursive: true });
mkdirSync("dist/renderer/icons/light", { recursive: true });
mkdirSync("dist/renderer/icons/dark", { recursive: true });
mkdirSync("dist/renderer/icons/logos", { recursive: true });
} catch (e) {
// Directory already exists
}
// Note: toolboxAPIBridge.js has been removed as tools now use toolPreloadBridge.ts via BrowserView preload
// Copy entire icons directory
const iconsLightSourceDir = "src/renderer/icons/light";
const iconsLightTargetDir = "dist/renderer/icons/light";
try {
if (existsSync(iconsLightSourceDir)) {
const iconFiles = readdirSync(iconsLightSourceDir);
iconFiles.forEach((file: string) => {
const sourcePath = path.join(iconsLightSourceDir, file);
const targetPath = path.join(iconsLightTargetDir, file);
copyFileSync(sourcePath, targetPath);
});
}
} catch (e) {
console.error(`Failed to copy icons directory:`, e);
}
const iconsDarkSourceDir = "src/renderer/icons/dark";
const iconsDarkTargetDir = "dist/renderer/icons/dark";
try {
if (existsSync(iconsDarkSourceDir)) {
const iconFiles = readdirSync(iconsDarkSourceDir);
iconFiles.forEach((file: string) => {
const sourcePath = path.join(iconsDarkSourceDir, file);
const targetPath = path.join(iconsDarkTargetDir, file);
copyFileSync(sourcePath, targetPath);
});
}
} catch (e) {
console.error(`Failed to copy icons directory:`, e);
}
const iconsLogosSourceDir = "src/renderer/icons/logos";
const iconsLogosTargetDir = "dist/renderer/icons/logos";
try {
if (existsSync(iconsLogosSourceDir)) {
const iconFiles = readdirSync(iconsLogosSourceDir);
iconFiles.forEach((file: string) => {
const sourcePath = path.join(iconsLogosSourceDir, file);
const targetPath = path.join(iconsLogosTargetDir, file);
copyFileSync(sourcePath, targetPath);
});
}
} catch (e) {
console.error(`Failed to copy icons directory:`, e);
}
// Copy registry.json for fallback when Supabase is not configured
const registrySource = "src/main/data/registry.json";
const registryTargetDir = "dist/main/data";
const registryTarget = path.join(registryTargetDir, "registry.json");
try {
if (existsSync(registrySource)) {
mkdirSync(registryTargetDir, { recursive: true });
copyFileSync(registrySource, registryTarget);
}
} catch (e) {
console.error(`Failed to copy registry.json:`, e);
}
},
},
],
// Define environment variables for renderer process as well
define: envDefines,
build: {
// Renderer process build configuration
// Only include source maps when not building for production
sourcemap: enableSourceMap,
outDir: "dist/renderer",
rollupOptions: {
input: path.resolve(__dirname, "src/renderer/index.html"),
output: {
// Configure code splitting
manualChunks: (id) => {
// Split vendor dependencies into separate chunk
if (id.includes("node_modules")) {
return "vendor";
}
},
},
plugins: [
// Bundle analysis for renderer process
visualizer({
filename: "dist/stats-renderer.html",
open: false,
gzipSize: true,
brotliSize: true,
}),
],
},
},
// Resolve aliases
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
// CSS preprocessing configuration
css: {
preprocessorOptions: {
scss: {
// Add global SCSS variables/mixins if needed
// additionalData: `@import "@/styles/variables.scss";`
},
},
},
// Dev server configuration
server: {
port: 5173,
},
// Base path for assets
base: "./",
// Copy static assets from src/renderer
publicDir: false,
};
});