-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
vite.config.js
68 lines (65 loc) · 2.15 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import dotenv from "dotenv";
import path from "path";
// Load environment variables from .env file
dotenv.config();
// Set the API URL based on environment variable or default
const apiUrl = process.env.VITE_API_URL || "https://api.thecyberhub.org";
export default defineConfig({
base: "./", // This is crucial for all relative paths
resolve: {
alias: {
src: path.resolve(__dirname, "./src"),
},
},
server: {
proxy: {
"/api": {
target: apiUrl,
changeOrigin: true,
secure: false,
},
},
host: "0.0.0.0",
port: 3000,
},
plugins: [
react(),
{
name: "rewrite-asset-paths",
enforce: "post",
generateBundle(options, bundle) {
// Process each chunk in the bundle
Object.keys(bundle).forEach((fileName) => {
const chunk = bundle[fileName];
if (chunk.type === "chunk" || chunk.type === "asset") {
// Replace absolute paths with relative paths in the content
if (typeof chunk.code === "string") {
chunk.code = chunk.code.replace(/["']\/assets\//g, '"./assets/');
}
if (chunk.source) {
chunk.source = chunk.source.toString().replace(/["']\/assets\//g, '"./assets/');
}
}
});
},
},
],
build: {
outDir: "dist",
emptyOutDir: true,
assetsDir: "assets",
rollupOptions: {
output: {
assetFileNames: "assets/[name].[hash][extname]",
chunkFileNames: "assets/[name].[hash].js",
entryFileNames: "assets/[name].[hash].js",
// Ensure proper path resolution
manualChunks: undefined,
},
},
// Generate source maps for better debugging
sourcemap: true,
},
});