Skip to content

Commit 66deaf2

Browse files
committed
Only try to connect to the dev tools in development
1 parent 61ed01f commit 66deaf2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4-
<!-- to use with external React Dev Tools -->
5-
<script src="http://localhost:8097"></script>
4+
<!-- REACT_DEVTOOLS_SCRIPT -->
65
<meta charset="UTF-8" />
76
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
87
<meta http-equiv="Content-Security-Policy" content="script-src 'self';" />

vite.config.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig, UserConfigExport } from 'vite'
1+
import { defineConfig, type Plugin, type UserConfigExport } from 'vite'
22
import electron from 'vite-plugin-electron'
33
import react from '@vitejs/plugin-react-swc'
44
import svgr from 'vite-plugin-svgr'
@@ -24,7 +24,20 @@ const electronViteConfig: UserConfigExport = {
2424
}
2525
}
2626

27-
export default defineConfig({
27+
// FIXME: Potentially publish this as a dedicated plugin, if other projects
28+
// run into the same issue
29+
const vite_plugin_react_dev_tools: Plugin = {
30+
name: 'react-dev-tools-replace',
31+
transformIndexHtml: {
32+
transform: (html) =>
33+
html.replace(
34+
'<!-- REACT_DEVTOOLS_SCRIPT -->',
35+
'<script src="http://localhost:8097"></script>'
36+
)
37+
}
38+
}
39+
40+
export default defineConfig(({ mode }) => ({
2841
build: {
2942
target: 'esnext',
3043
outDir: 'build'
@@ -51,6 +64,7 @@ export default defineConfig({
5164
onstart: ({ reload }) => reload()
5265
}
5366
]),
54-
svgr()
67+
svgr(),
68+
mode !== 'production' && vite_plugin_react_dev_tools
5569
]
56-
})
70+
}))

0 commit comments

Comments
 (0)