Skip to content

Commit

Permalink
fix(debug): inject import.env
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Dec 3, 2024
1 parent 5fec56e commit 810516a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/renderer/debug_proxy.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Debug Proxy</title>

<script>
<script type="module">
globalThis["__DEBUG_PROXY__"] = true

const searchParams = new URLSearchParams(window.location.search)
Expand Down
12 changes: 9 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copyFileSync, existsSync } from "node:fs"
import { existsSync, readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"
import { fileURLToPath } from "node:url"

Expand Down Expand Up @@ -288,7 +288,7 @@ function checkBrowserSupport() {
}
}

const htmlPlugin: (env: any) => PluginOption = () => {
const htmlPlugin: (env: any) => PluginOption = (env) => {
let config: ResolvedConfig
return {
name: "html-transform",
Expand All @@ -302,7 +302,13 @@ const htmlPlugin: (env: any) => PluginOption = () => {
const debugProxyHtml = resolve(root, "debug_proxy.html")

if (existsSync(debugProxyHtml)) {
copyFileSync(debugProxyHtml, resolve(dist, "__debug_proxy.html"))
const content = readFileSync(debugProxyHtml, "utf-8")

writeFileSync(
resolve(dist, "__debug_proxy.html"),

content.replace("import.meta.env.VITE_API_URL", `"${env.VITE_API_URL}"`),
)
}
},
transformIndexHtml(html) {
Expand Down

0 comments on commit 810516a

Please sign in to comment.