-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvite.config.ts
More file actions
68 lines (64 loc) · 1.93 KB
/
vite.config.ts
File metadata and controls
68 lines (64 loc) · 1.93 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
import { execSync } from "child_process";
import { readFileSync } from "fs";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import { devArtifactsPlugin } from "./vite-plugin-artifacts";
// Get version from package.json
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
const appVersion = packageJson.version || "0.0.0";
// Get git commit hash
let commitHash = "development";
try {
commitHash = execSync("git rev-parse HEAD").toString().trim();
} catch {
console.warn("Could not get git commit hash");
}
const isGhPages = process.env.GITHUB_PAGES === "true";
const base = isGhPages ? "/explorer/" : "/";
export default defineConfig({
base,
plugins: [react(), devArtifactsPlugin()],
server: {
port: 3030,
open: true,
},
preview: {
port: 3030,
},
build: {
outDir: "dist",
sourcemap: false,
minify: "terser",
terserOptions: {
mangle: {
safari10: true,
},
compress: {
drop_console: false,
drop_debugger: false,
pure_funcs: process.env.NODE_ENV === "production" ? ["console.log"] : [],
},
},
},
define: {
"process.env.REACT_APP_COMMIT_HASH": JSON.stringify(
process.env.REACT_APP_COMMIT_HASH || commitHash
),
"process.env.REACT_APP_GITHUB_REPO": JSON.stringify(
process.env.REACT_APP_GITHUB_REPO ||
"https://github.com/openscan-explorer/explorer"
),
"process.env.REACT_APP_VERSION": JSON.stringify(
process.env.REACT_APP_VERSION || appVersion
),
"process.env.REACT_APP_OPENSCAN_NETWORKS": JSON.stringify(
process.env.REACT_APP_OPENSCAN_NETWORKS || ""
),
"process.env.REACT_APP_OPENSCAN_WORKER_URL": JSON.stringify(
process.env.REACT_APP_OPENSCAN_WORKER_URL || "https://openscan-worker-proxy.openscan.workers.dev"
),
"import.meta.env.VITE_ENVIRONMENT": JSON.stringify(
process.env.NODE_ENV || "development"
),
},
});