-
Notifications
You must be signed in to change notification settings - Fork 108
/
vite.config.js
84 lines (81 loc) · 2.19 KB
/
vite.config.js
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
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import react from '@vitejs/plugin-react'
import process from 'process/browser'
import { defineConfig, loadEnv } from 'vite'
import svgr from 'vite-plugin-svgr'
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_')
const port = parseInt(env.VITE_PORT ?? '3000')
const base = command === 'build' ? '/embed/' : '/'
return {
base,
build: {
outDir: 'build',
sourcemap: true,
commonjsOptions: {
include: [/libs\/dist\/web-libs/, /node_modules/]
}
},
define: {
// Using `process.env` to support mobile,
// This can be removed once the common migration is complete
'process.env': env
},
optimizeDeps: {
include: ['@audius/sdk-legacy/dist/web-libs', '@audius/fetch-nft'],
esbuildOptions: {
define: {
global: 'globalThis'
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true
})
]
}
},
plugins: [
svgr({
include: '**/*.svg'
}),
// Import workerscript as raw string
// Could use ?raw suffix but it breaks on mobile
{
transform(code, id) {
if (/\.workerscript$/.test(id)) {
const str = JSON.stringify(code)
return {
code: `export default ${str}`
}
}
}
},
react({
jsxImportSource: '@emotion/react',
babel: {
plugins: ['@emotion/babel-plugin']
}
})
],
resolve: {
alias: {
os: require.resolve('os-browserify'),
path: require.resolve('path-browserify'),
url: require.resolve('url'),
zlib: require.resolve('browserify-zlib'),
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
stream: require.resolve('stream-browserify'),
// Resolve to lodash-es to support tree-shaking
lodash: 'lodash-es'
}
},
server: {
port
},
test: {
environment: 'jsdom'
}
}
})