-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathvite.config.ts
More file actions
48 lines (44 loc) · 1.45 KB
/
Copy pathvite.config.ts
File metadata and controls
48 lines (44 loc) · 1.45 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
const glReactSrc = /\/packages\/gl-react(-dom)?\/src\/.*\.tsx?$/
// Shim Node.js `global` → `globalThis` for browser compat in gl-react sources
const glReactGlobalShim = () => ({
name: 'gl-react-global-shim',
enforce: 'pre' as const,
transform(code: string, id: string) {
if (!glReactSrc.test(id)) return null
const shimmed = code.replace(/\bglobal\b(?!This)/g, 'globalThis')
if (shimmed === code) return null
return { code: shimmed, map: null }
},
})
// When deploying to GitHub Pages under https://gre.github.io/gl-react/
// the assets and routes must be served from the /gl-react/ subpath.
// Set GH_PAGES=true in the deploy workflow to switch the base.
const base = process.env.GH_PAGES === 'true' ? '/gl-react/' : '/'
export default defineConfig({
base,
plugins: [glReactGlobalShim(), react()],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'gl-react': resolve(__dirname, '../gl-react/src'),
'gl-react-dom': resolve(__dirname, '../gl-react-dom/src'),
'gl-react-blur': resolve(__dirname, '../gl-react-blur/src'),
'gl-react-image': resolve(__dirname, '../gl-react-image/src'),
buffer: resolve(__dirname, './src/shims/buffer.ts'),
},
},
server: {
port: 3001,
open: true,
},
define: {
global: 'globalThis',
},
build: {
outDir: 'dist',
sourcemap: true,
},
})