-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvite.config.ts
More file actions
104 lines (99 loc) · 2.62 KB
/
vite.config.ts
File metadata and controls
104 lines (99 loc) · 2.62 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
103
104
import { defineConfig } from 'vite'
import GlobalPolyFill from "@esbuild-plugins/node-globals-polyfill";
import nodePolyfills from 'rollup-plugin-node-polyfills';
import inject from '@rollup/plugin-inject'
import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr';
import { comlink } from 'vite-plugin-comlink'
import { resolve } from 'path';
import basicSsl from '@vitejs/plugin-basic-ssl'
import fs from 'fs'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const certPath = path.resolve(__dirname, 'localhost+2.pem')
const keyPath = path.resolve(__dirname, 'localhost+2-key.pem')
let httpsConfig
let useBasicSsl = false
if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
console.log('✓ Using mkcert certificates')
httpsConfig = {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
}
} else {
console.log('⚠ mkcert certificates not found, using basicSsl')
console.log(' Run: mkcert localhost 127.0.0.1 ::1')
httpsConfig = true
useBasicSsl = true
}
return {
server: {
port: 3000,
https: httpsConfig,
},
plugins: [
comlink(),
...(useBasicSsl ? [basicSsl()] : []),
svgr(),
react(),
],
resolve: {
alias: [
{ find: 'process', replacement: 'process/browser' },
{ find: 'stream', replacement: 'stream-browserify' },
{ find: 'https', replacement: 'agent-base' },
...[
'assets',
'components',
'form',
'indigo-react',
'lib',
'store',
'style',
'views',
'worker',
].map(a => ({ find: a, replacement: resolve(__dirname, `src/${a}`) })),
],
},
worker: {
plugins: [
comlink(),
],
},
build: Object.assign(
{
outDir: 'build',
rollupOptions: {
plugins: [nodePolyfills()],
},
},
mode === 'development' ? { global: {} } : {}
),
optimizeDeps: {
include: ['urbit-key-generation'],
esbuildOptions: {
define: {
global: 'globalThis',
},
plugins: [
GlobalPolyFill({
process: true,
buffer: true,
}),
],
},
},
define: Object.assign({
// https://github.com/origamitower/folktale/issues/229
"process.env.FOLKTALE_DOCS": false,
"process.env.FOLKTALE_ASSERTIONS": false,
},
mode === 'production' ? {
rollupOptions: {
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
},
} : {}
)
};
});