This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
79 lines (76 loc) · 2.27 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
import { defineConfig, Plugin, ResolvedConfig } from "vite";
import reactPlugin from '@vitejs/plugin-react'
import { writeFile, mkdir } from 'fs/promises'
import path from 'path'
import reactRefresh from '@vitejs/plugin-react-refresh'
// Hard-coded for now
// - assume index is "/src/main.tsx"
// - assume body has div#app
// - preamble code is better read from reactRefresh instead
const devIndexHtmlPlugin: () => Plugin = () => {
let config: ResolvedConfig
return {
name: 'vite:logseq-dev-index-html-plugin',
enforce: 'pre',
apply: 'serve',
configResolved(resolvedConfig) {
// store the resolved config
config = resolvedConfig
},
buildStart: async (opt) => {
const template = `
<!DOCTYPE html>
<html lang="en">
<head>
<base href="http://${config.server.host}:${config.server.port}">
<meta charset="UTF-8" />
<script type="module" src="/@vite/client"></script>
<script type="module">
import RefreshRuntime from "/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
</script>
<link rel="icon" type="image/svg+xml" href="logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Plugin</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
`
await mkdir(config.build.outDir, { recursive: true })
await writeFile(
path.resolve(config.build.outDir, 'index.html'),
template,
{
encoding: 'utf-8',
}
)
console.info('Wrote development index.html')
},
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [reactRefresh, reactPlugin(), devIndexHtmlPlugin()],
base: '',
clearScreen: false,
// Makes HMR available for development
server: {
cors: true,
host: 'localhost',
hmr: {
host: 'localhost',
},
port: 4567,
strictPort: true,
},
build: {
target: 'esnext',
minify: 'esbuild',
},
})