-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvite.config.ts
More file actions
154 lines (142 loc) · 4.08 KB
/
vite.config.ts
File metadata and controls
154 lines (142 loc) · 4.08 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
import path from "node:path";
import { fileURLToPath } from "node:url";
import { execSync } from "child_process";
import { livestoreDevtoolsPlugin } from "@livestore/devtools-vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig, loadEnv } from "vite";
import { visualizer } from "rollup-plugin-visualizer";
import { injectLoadingScreen } from "./vite-plugins/inject-loading-screen.js";
import { envValidationPlugin } from "./vite-plugins/env-validation.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
// Get git commit hash - check various CI environments
let gitCommitHash =
process.env.VITE_GIT_COMMIT_HASH || // Explicitly set
process.env.WORKERS_CI_COMMIT_SHA || // Cloudflare
process.env.GITHUB_SHA?.substring(0, 7); // GitHub Actions (short SHA)
if (!gitCommitHash) {
try {
// Get the commit hash
gitCommitHash = execSync("git rev-parse --short HEAD", {
encoding: "utf8",
}).trim();
// Check if the working directory is dirty
const isDirty =
execSync("git status --porcelain", {
encoding: "utf8",
}).trim().length > 0;
if (isDirty) {
gitCommitHash += "-dirty";
}
} catch (e) {
// Fallback when git info is not available (e.g., in CI or non-git directory)
console.error("git command error:", e);
gitCommitHash = "unknown";
}
}
const plugins = [
envValidationPlugin(env),
injectLoadingScreen(),
react({
babel: {
plugins: [
[
"babel-plugin-react-compiler",
{
// Enable React Compiler
enable: true,
// Optional: Configure which files to compile
include: ["src/**/*.{js,jsx,ts,tsx}"],
// Optional: Exclude certain files
exclude: [
"src/**/*.test.{js,jsx,ts,tsx}",
"src/**/*.spec.{js,jsx,ts,tsx}",
],
},
],
],
},
}),
tailwindcss(),
];
if (env.ENABLE_LIVESTORE_DEVTOOLS === "true") {
plugins.push(
livestoreDevtoolsPlugin({
schemaPath: "./packages/schema/src/index.ts",
})
);
}
// Add bundle analyzer for bundle analysis
if (process.env.ANALYZE_BUNDLE) {
plugins.push(
visualizer({
filename: "dist/bundle-analysis.html",
open: true,
gzipSize: true,
brotliSize: true,
})
);
}
// Include Cloudflare plugin in development and auth modes
if (mode === "development" || mode === "auth") {
// TODO: This isn't working with SPA
// Even with the symlink, this 307 redirects /oidc?code to /oidc/code
// which breaks the auth flow.
// plugins.push(
// cloudflare({
// configPath: "./wrangler.toml",
// })
// );
}
return {
mode,
build: {
sourcemap: true,
},
server: {
host: "0.0.0.0", // Allow external access (needed for Docker)
port: env.ANODE_DEV_SERVER_PORT
? parseInt(env.ANODE_DEV_SERVER_PORT)
: 5173,
strictPort: true,
proxy: {
"/api": {
target: env.VITE_API_TARGET || "http://localhost:8787",
changeOrigin: true,
},
"/graphql": {
target: env.VITE_API_TARGET || "http://localhost:8787",
changeOrigin: true,
},
},
},
cacheDir: "node_modules/.vite-main",
worker: { format: "es" },
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
optimizeDeps: {
exclude: ["@livestore/wa-sqlite", "pyodide"],
include: [
"react",
"react-dom",
"effect",
"@livestore/livestore",
"@livestore/react",
"@react-spring/web",
],
esbuildOptions: {
target: "esnext",
},
},
assetsInclude: ["**/*.wasm"],
plugins,
define: {
"import.meta.env.VITE_GIT_COMMIT_HASH": JSON.stringify(gitCommitHash),
},
};
});