forked from dydxprotocol/v4-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
92 lines (89 loc) · 2.32 KB
/
vite.config.ts
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
import react from '@vitejs/plugin-react';
import fs from 'fs';
import path from 'path';
import sourcemaps from 'rollup-plugin-sourcemaps';
import { defineConfig } from 'vite';
import ViteRestart from 'vite-plugin-restart';
import svgr from 'vite-plugin-svgr';
const entryPointsDir = path.join(__dirname, 'entry-points');
const entryPointsExist = fs.existsSync(entryPointsDir);
const entryPoints = entryPointsExist
? fs.readdirSync(entryPointsDir).map((file) => `/entry-points/${file}`)
: [];
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
define: {
'process.env': {},
},
rollupOptions: {
// Needed for Abacus sourcemaps since Rollup doesn't load external sourcemaps by default.
// https://github.com/vitejs/vite/issues/11743
plugins: mode === 'development' ? [sourcemaps()] : [],
},
resolve: {
alias: [
{ find: '@', replacement: path.resolve(__dirname, 'src') },
{ find: 'public', replacement: path.resolve(__dirname, 'public') },
{
find: 'stream',
replacement: 'stream-browserify',
},
{
find: 'assert',
replacement: 'assert',
},
{
find: 'url',
replacement: 'url-polyfill',
},
{
find: 'util',
replacement: 'util/',
},
{
find: 'zlib',
replacement: 'browserify-zlib',
},
],
},
plugins: [
react({
babel: {
plugins: [
[
'babel-plugin-styled-components',
{
displayName: mode === 'development',
},
],
],
},
}),
svgr({
exportAsDefault: true,
}),
// Currently, the Vite file watcher is unable to watch folders within node_modules.
// Workaround is to use ViteRestart plugin + a generated file to trigger the restart.
// See https://github.com/vitejs/vite/issues/8619
ViteRestart({
restart: ['local-abacus-hash'],
}),
],
publicDir: 'public',
test: {
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/e2e/**',
],
environment: 'jsdom',
},
build: {
rollupOptions: {
input: entryPoints,
},
},
}));