Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
88 lines (84 loc) · 2.62 KB
/
Copy pathvite.config.js
File metadata and controls
88 lines (84 loc) · 2.62 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
function pwaHeaders() {
const applyHeaders = (req, res, next) => {
if (req.url === "/manifest.json") {
res.setHeader("Content-Type", "application/manifest+json");
}
next();
};
return {
name: "fintrackr-pwa-headers",
configureServer(server) {
server.middlewares.use(applyHeaders);
},
configurePreviewServer(server) {
server.middlewares.use(applyHeaders);
}
};
}
function serviceWorkerVersion() {
return {
name: "fintrackr-sw-version",
closeBundle() {
const version = process.env.VITE_BUILD_VERSION || `build-${Date.now()}`;
const swPath = join(process.cwd(), "app", "static", "service-worker.js");
try {
const content = readFileSync(swPath, "utf-8");
writeFileSync(swPath, content.replace(/__CACHE_VERSION__/g, version));
} catch {
// service-worker.js not in build output — skip
}
},
};
}
export default defineConfig({
root: "app",
plugins: [react(), pwaHeaders(), serviceWorkerVersion()],
resolve: {
// TS/TSX must win over same-named JS/JSX during the incremental migration,
// otherwise a stale .js/.jsx left behind after a rename silently shadows
// its typed replacement instead of erroring.
extensions: [".mjs", ".mts", ".ts", ".tsx", ".js", ".jsx", ".json"]
},
esbuild: {
// Strip debug output from production bundles. Vite only applies this to
// `vite build`, so the dev server keeps full logging.
drop: ["console", "debugger"]
},
build: {
outDir: "static",
emptyOutDir: true,
sourcemap: false,
// Warn earlier than the 500 kB default so bundle growth is visible.
chunkSizeWarningLimit: 600,
rollupOptions: {
output: {
// Split the heavy, rarely-changing vendor code into its own chunks so
// they stay cached across app deploys.
manualChunks: {
"vendor-react": ["react", "react-dom", "react-router-dom"],
"vendor-charts": ["recharts"],
"vendor-query": ["@tanstack/react-query"],
"vendor-mui": ["@mui/material", "@emotion/react", "@emotion/styled"],
"vendor-mui-datagrid": ["@mui/x-data-grid"]
}
}
}
},
server: {
port: 3000,
proxy: {
"/api": {
target: process.env.VITE_API_TARGET || "http://localhost:8000",
changeOrigin: true
},
"/runtime-config.js": {
target: process.env.VITE_API_TARGET || "http://localhost:8000",
changeOrigin: true
}
}
}
});