forked from vipineth/hypeterminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
197 lines (190 loc) · 7.31 KB
/
vite.config.ts
File metadata and controls
197 lines (190 loc) · 7.31 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import tailwindcss from '@tailwindcss/vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import viteReact from '@vitejs/plugin-react'
import { nitro } from 'nitro/vite'
import { defineConfig, type PluginOption } from 'vite'
import viteTsConfigPaths from 'vite-tsconfig-paths'
import { lingui } from '@lingui/vite-plugin'
import { visualizer } from 'rollup-plugin-visualizer'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const isAnalyze = process.env.ANALYZE === 'true'
const eventsPolyfill = resolve(dirname(fileURLToPath(import.meta.url)), 'node_modules/events/events.js')
const browserOnlyModules: Record<string, string> = {
klinecharts: `
export const init = () => ({});
export const dispose = () => {};
export const FormatDateType = {};
export const LoadDataType = {};
export const CandleType = {};
export const LineType = {};
export const TooltipShowRule = {};
export const TooltipShowType = {};
export const YAxisPosition = {};
export default {};
`,
'motion/react': `
import { createElement, forwardRef } from 'react';
const el = (tag) => forwardRef(({ children, animate, initial, exit, transition, variants,
whileHover, whileTap, whileFocus, whileInView, whileDrag, drag, dragConstraints,
layout, layoutId, onAnimationStart, onAnimationComplete, ...rest }, ref) =>
createElement(tag, { ...rest, ref }, children));
export const motion = new Proxy({}, { get: (_, tag) => el(tag) });
export const m = motion;
export const AnimatePresence = ({ children }) => children;
export const MotionConfig = ({ children }) => children;
export const LazyMotion = ({ children }) => children;
export const useReducedMotion = () => null;
export const domAnimation = {};
export const domMax = {};
export default {};
`,
wagmi: `
import { createElement } from 'react';
export const WagmiProvider = ({ children }) => children;
export const createConfig = () => ({});
export const http = () => ({});
export const useAccount = () => ({ address: undefined, isConnected: false, status: 'disconnected' });
export const useBalance = () => ({ data: undefined, isLoading: false, error: null });
export const useConnect = () => ({ connect: () => {}, connectors: [], status: 'idle', error: null });
export const useConnectors = () => [];
export const useConnection = () => ({ address: undefined, isConnected: false, connector: null, status: 'disconnected' });
export const useDisconnect = () => ({ disconnect: () => {} });
export const useEnsName = () => ({ data: undefined, isLoading: false });
export const useSwitchChain = () => ({ switchChain: () => {}, chains: [], status: 'idle', error: null });
export const useWalletClient = () => ({ data: null, isLoading: false, error: null });
export const usePublicClient = () => undefined;
export const useChainId = () => 42161;
export const useSignMessage = () => ({ signMessage: () => {}, status: 'idle', data: undefined });
export const useWriteContract = () => ({ writeContract: () => {}, status: 'idle', data: undefined });
export const useWaitForTransactionReceipt = () => ({ data: undefined, isLoading: false, status: 'idle', error: null });
export const useReadContract = () => ({ data: undefined, isLoading: false, error: null });
export const serialize = (x) => JSON.stringify(x);
export const deserialize = JSON.parse;
export const cookieToInitialState = () => undefined;
export const cookieStorage = {};
export default {};
`,
'wagmi/connectors': `
export const injected = () => ({});
export const coinbaseWallet = () => ({});
export const walletConnect = () => ({});
export const mock = () => ({});
export default {};
`,
'@privy-io/react-auth': `
import { createElement } from 'react';
export const PrivyProvider = ({ children }) => children;
export const usePrivy = () => ({ ready: true, authenticated: false, user: null, login: () => {}, logout: async () => {} });
export const useLogin = () => ({ login: () => {} });
export const useLogout = () => ({ logout: async () => {} });
export const useWallets = () => ({ wallets: [], ready: true });
export const toViemAccount = async () => null;
export default {};
`,
'@privy-io/wagmi': `
import { createElement } from 'react';
export const WagmiProvider = ({ children }) => children;
export const createConfig = () => ({});
export const useSetActiveWallet = () => ({ setActiveWallet: async () => {} });
export default {};
`,
}
const ssrStubPlugin = {
name: 'ssr-stub-browser-only-modules',
enforce: 'pre' as const,
resolveId(id: string, _: string | undefined, options: { ssr?: boolean } | undefined) {
if (options?.ssr && id in browserOnlyModules) return `\0virtual:${id}`
},
load(id: string) {
const name = id.replace('\0virtual:', '')
if (name in browserOnlyModules) return browserOnlyModules[name]
},
}
const eventsPolyfillPlugin = {
name: 'polyfill-events-for-browser',
enforce: 'pre' as const,
resolveId(id: string, _: string | undefined, options: { ssr?: boolean } | undefined) {
if (!options?.ssr && (id === 'events' || id === 'node:events')) return eventsPolyfill
},
}
function createManualChunks(id: string) {
if (id.includes('node_modules')) {
if (id.includes('@radix-ui')) return 'vendor-radix'
if (id.includes('@tanstack/react-query') || id.includes('@tanstack/react-table') || id.includes('@tanstack/react-virtual')) return 'vendor-tanstack'
if (id.includes('recharts') || id.includes('d3-')) return 'vendor-charts'
if (id.includes('klinecharts')) return 'vendor-klinecharts'
}
}
const config = defineConfig({
server: {
strictPort: false,
},
build: {
sourcemap: isAnalyze,
},
environments: {
client: {
build: {
rollupOptions: {
output: {
manualChunks: createManualChunks,
},
},
},
},
},
plugins: [
eventsPolyfillPlugin,
nodePolyfills({ include: ['buffer'], globals: { Buffer: true, global: true } }),
ssrStubPlugin,
nitro({
preset: 'cloudflare-pages',
compressPublicAssets: true,
minify: true,
rollupConfig: {
output: {
inlineDynamicImports: true,
},
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
unknownGlobalSideEffects: false,
},
},
routeRules: {
'/assets/**': {
headers: { 'cache-control': 'public, max-age=31536000, immutable' },
},
'/charting_library/**': {
headers: { 'cache-control': 'public, max-age=31536000, immutable' },
},
},
}),
lingui(),
viteTsConfigPaths({
projects: ['./tsconfig.json'],
}),
tailwindcss(),
tanstackStart({
router: {
autoCodeSplitting: true,
},
}),
viteReact({
babel: {
plugins: ['@lingui/babel-plugin-lingui-macro', 'babel-plugin-react-compiler'],
},
}),
isAnalyze &&
(visualizer({
filename: 'dist/stats.html',
open: true,
gzipSize: true,
brotliSize: true,
template: 'treemap',
}) as PluginOption),
].filter(Boolean),
})
export default config