-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvite.config.ts
More file actions
158 lines (143 loc) · 4.63 KB
/
vite.config.ts
File metadata and controls
158 lines (143 loc) · 4.63 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
/// <reference types='vitest' />
import { createRequire } from 'node:module';
import path from 'node:path';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
const require = createRequire(import.meta.url);
const readableStreamPath = path.dirname(
require.resolve('readable-stream/package.json'),
);
const COMMIT_SHA =
process.env['GIT_COMMIT_SHA'] ??
process.env['NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA'] ??
process.env['VERCEL_GIT_COMMIT_SHA'];
const distDir = '../../dist/apps/vesting';
export default defineConfig(async () => {
const { default: tailwindcss } = await import('@tailwindcss/vite');
return {
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/vesting',
server: {
port: 4200,
host: 'localhost',
},
preview: {
port: 4300,
host: 'localhost',
},
plugins: [
react(),
nxViteTsPaths(),
nodePolyfills({
globals: {
Buffer: true,
global: true,
process: true,
},
protocolImports: true,
}),
tailwindcss(),
sentryVitePlugin({
org: 'haqq-network',
project: 'vesting-app',
authToken: process.env['SENTRY_AUTH_TOKEN'],
release: {
name: COMMIT_SHA ?? 'development',
inject: false, // Avoid virtual module conflict with readable-stream/commonjs
deploy: {
env: process.env['VERCEL_ENV'] ?? 'development',
},
dist: distDir,
},
reactComponentAnnotation: {
enabled: true,
},
}),
],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
build: {
outDir: distDir,
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
include: [/node_modules/],
},
rollupOptions: {
// Ensure readable-stream and deps are bundled (no bare specifiers in output)
external: (id) => {
if (id === 'sentry-release-injection-file') return false;
if (id.startsWith('readable-stream')) return false;
return undefined;
},
},
sourcemap: true,
},
resolve: {
dedupe: ['buffer', 'readable-stream'],
alias: [
// CJS process shim so readable-stream/process-nextick-args get process.nextTick (see readable-stream#539)
{
find: 'process',
replacement: path.resolve(__dirname, 'process-shim.js'),
},
// Force bundle readable-stream so no bare specifiers reach the browser
{
find: /^readable-stream\/lib\/_stream_readable\.js$/,
replacement: path.join(readableStreamPath, 'lib/_stream_readable.js'),
},
{
find: /^readable-stream\/lib\/_stream_writable\.js$/,
replacement: path.join(readableStreamPath, 'lib/_stream_writable.js'),
},
{
find: /^readable-stream\/lib\/_stream_duplex\.js$/,
replacement: path.join(readableStreamPath, 'lib/_stream_duplex.js'),
},
{
find: /^readable-stream\/lib\/_stream_transform\.js$/,
replacement: path.join(
readableStreamPath,
'lib/_stream_transform.js',
),
},
{
find: /^readable-stream\/lib\/_stream_passthrough\.js$/,
replacement: path.join(
readableStreamPath,
'lib/_stream_passthrough.js',
),
},
{
find: /^readable-stream\/readable-browser\.js$/,
replacement: path.join(readableStreamPath, 'readable-browser.js'),
},
{ find: 'readable-stream', replacement: readableStreamPath },
],
},
optimizeDeps: {
include: ['buffer', 'readable-stream'],
},
define: {
// readable-stream and other Node deps expect process.version (e.g. process.version.slice(0, 5))
'process.version': JSON.stringify('v18.0.0'),
'process.env.GIT_COMMIT_SHA': JSON.stringify(COMMIT_SHA),
'process.env.WALLETCONNECT_PROJECT_ID': JSON.stringify(
process.env['WALLETCONNECT_PROJECT_ID'],
),
'process.env.POSTHOG_KEY': JSON.stringify(
process.env['NEXT_PUBLIC_POSTHOG_KEY'],
),
'process.env.POSTHOG_HOST': JSON.stringify(
process.env['NEXT_PUBLIC_POSTHOG_HOST'],
),
'process.env.SENTRY_DSN': JSON.stringify(process.env['SENTRY_DSN']),
},
};
});