-
-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathvite.config.mjs
More file actions
102 lines (97 loc) · 2.47 KB
/
Copy pathvite.config.mjs
File metadata and controls
102 lines (97 loc) · 2.47 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
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
import fs from 'node:fs'
import path from 'node:path'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
const root = path.resolve(__dirname)
const rootSrc = path.resolve(__dirname, 'src')
const rootRenderer = path.resolve(__dirname, 'src/renderer')
const excalidrawFontsDir = path.join(
fs.realpathSync(path.resolve(__dirname, 'node_modules/@excalidraw/excalidraw')),
'dist/prod/fonts',
)
// Self-hosts Excalidraw fonts so drawings work offline:
// serves them at /fonts in dev and copies them next to index.html on build.
function excalidrawFonts() {
return {
name: 'masscode:excalidraw-fonts',
configureServer(server) {
server.middlewares.use('/fonts', (req, res, next) => {
const requestPath = decodeURIComponent(
(req.url || '').split('?')[0],
).replace(/^\/+/, '')
const filePath = path.join(excalidrawFontsDir, requestPath)
if (
!filePath.startsWith(excalidrawFontsDir)
|| !fs.existsSync(filePath)
|| !fs.statSync(filePath).isFile()
) {
next()
return
}
res.setHeader('Content-Type', 'font/woff2')
fs.createReadStream(filePath).pipe(res)
})
},
writeBundle() {
fs.cpSync(
excalidrawFontsDir,
path.resolve(__dirname, 'build/renderer/fonts'),
{ recursive: true },
)
},
}
}
export default defineConfig({
root: rootRenderer,
base: './',
plugins: [
vue(),
tailwindcss(),
AutoImport({
imports: ['vue'],
}),
Components({
dirs: [`${rootRenderer}/components`],
extensions: ['vue'],
dts: true,
directoryAsNamespace: true,
collapseSamePrefixes: true,
}),
excalidrawFonts(),
],
build: {
outDir: path.resolve(__dirname, 'build/renderer'),
emptyOutDir: true,
target: 'es2022',
},
optimizeDeps: {
esbuildOptions: {
target: 'es2022',
},
},
resolve: {
alias: {
'@': rootRenderer,
'~': rootSrc,
},
},
define: {
'process.env': {},
'process': {},
},
server: {
port: Number(process.env.DEV_PORT) || 5177,
strictPort: true,
watch: {
ignored: [
`${root}/src/main/i18n/locales/**/*`,
`${root}/scripts/**/*`,
`${root}/build/**/*`,
`${root}/src/main/**/*`,
],
},
},
})