forked from RSSNext/Follow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
119 lines (110 loc) · 3.36 KB
/
vite.config.ts
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
import { readFileSync } from "node:fs"
import { resolve } from "node:path"
import { fileURLToPath } from "node:url"
import { sentryVitePlugin } from "@sentry/vite-plugin"
import react from "@vitejs/plugin-react"
import { visualizer } from "rollup-plugin-visualizer"
import type { PluginOption } from "vite"
import { defineConfig, loadEnv } from "vite"
import mkcert from "vite-plugin-mkcert"
import { getGitHash } from "./scripts/lib"
import type { env as EnvType } from "./src/env"
const pkg = JSON.parse(readFileSync("package.json", "utf8"))
const __dirname = fileURLToPath(new URL(".", import.meta.url))
const isCI = process.env.CI === "true" || process.env.CI === "1"
const ROOT = "./src/renderer"
const vite = ({ mode }) => {
const env = loadEnv(mode, process.cwd())
const typedEnv = env as typeof EnvType
return defineConfig({
build: {
outDir: resolve(__dirname, "out/web"),
target: "ES2022",
sourcemap: isCI,
rollupOptions: {
input: {
main: resolve(ROOT, "/index.html"),
__debug_proxy: resolve(ROOT, "/__debug_proxy.html"),
},
},
},
root: ROOT,
envDir: resolve(__dirname, "."),
resolve: {
alias: {
"@renderer": resolve("src/renderer/src"),
"@shared": resolve("src/shared/src"),
"@pkg": resolve("./package.json"),
"@env": resolve("./src/env.ts"),
},
},
base: "/",
server: {
port: 2233,
},
plugins: [
htmlPlugin(typedEnv),
react(),
mkcert(),
sentryVitePlugin({
org: "follow-rg",
project: "follow",
disable: !isCI,
bundleSizeOptimizations: {
excludeDebugStatements: true,
// Only relevant if you added `browserTracingIntegration`
excludePerformanceMonitoring: true,
// Only relevant if you added `replayIntegration`
excludeReplayIframe: true,
excludeReplayShadowDom: true,
excludeReplayWorker: true,
},
moduleMetadata: {
appVersion:
process.env.NODE_ENV === "development" ? "dev" : pkg.version,
electron: false,
},
sourcemaps: {
filesToDeleteAfterUpload: ["out/web/assets/*.js.map"],
},
}),
process.env.ANALYZER && visualizer({ open: true }),
],
define: {
APP_VERSION: JSON.stringify(pkg.version),
APP_NAME: JSON.stringify(pkg.name),
APP_DEV_CWD: JSON.stringify(process.cwd()),
GIT_COMMIT_SHA: JSON.stringify(
process.env.VERCEL_GIT_COMMIT_SHA || getGitHash(),
),
DEBUG: process.env.DEBUG === "true",
ELECTRON: "false",
},
})
}
export default vite
function htmlPlugin(env: typeof EnvType): PluginOption {
return {
name: "html-transform",
enforce: "post",
transformIndexHtml(html) {
return html.replace(
"<!-- FOLLOW VITE BUILD INJECT -->",
`<script id="env_injection" type="module">
${function injectEnv(env: any) {
for (const key in env) {
if (env[key] === undefined) continue
globalThis["__followEnv"] ??= {}
globalThis["__followEnv"][key] = env[key]
}
}.toString()}
injectEnv(${JSON.stringify({
VITE_API_URL: env.VITE_API_URL,
VITE_WEB_URL: env.VITE_WEB_URL,
VITE_IMGPROXY_URL: env.VITE_IMGPROXY_URL,
})})
</script>`,
)
},
}
}