forked from beefyfinance/beefy-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
142 lines (135 loc) · 3.48 KB
/
Copy pathvite.config.ts
File metadata and controls
142 lines (135 loc) · 3.48 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
import { defineConfig, type Plugin } from 'vite';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import RollupNodePolyFillPlugin from 'rollup-plugin-polyfill-node';
import react from '@vitejs/plugin-react';
import svgrPlugin from 'vite-plugin-svgr';
import eslint from 'vite-plugin-eslint';
import { visualizer } from 'rollup-plugin-visualizer';
import * as path from 'node:path';
import versionPlugin from './version-plugin';
const optionalPlugins: Plugin[] = [];
if (process.env.NODE_ENV === 'development') {
optionalPlugins.push(
eslint({
failOnError: false,
failOnWarning: false,
})
);
}
if (process.env.ANALYZE_BUNDLE) {
optionalPlugins.push(
visualizer({
template: 'treemap', // or treemap/sunburst
open: true,
gzipSize: true,
brotliSize: true,
filename: 'analyze.html',
})
);
}
function getChunkName(absolutePath: string): string | undefined {
const relativePath = path.relative(__dirname, absolutePath).replace(/\\/g, '/');
const parts = relativePath.split('/');
if (parts.length < 2) {
return;
}
if (parts[0] === 'node_modules') {
const packageParts = parts.slice(1);
let packageName = packageParts[0];
if (packageName.startsWith('@')) {
packageName = packageName.substring(1);
if (packageParts.length > 1) {
packageName += '-' + packageParts[1];
}
}
return packageName.toLowerCase();
}
if (parts[0] === 'src') {
return parts[parts.length - 2].toLowerCase();
}
}
// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
},
plugins: [
react(),
{
...svgrPlugin(),
enforce: 'post',
},
versionPlugin(),
...optionalPlugins,
],
optimizeDeps: {
esbuildOptions: {
define: { global: 'globalThis' },
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
],
},
},
build: {
outDir: 'build',
assetsInlineLimit: 0,
sourcemap: false,
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
output: {
manualChunks: id => {
if (id.includes('@material-ui')) {
return 'material-ui';
}
if (id.includes('node_modules/lodash')) {
return 'lodash';
}
},
entryFileNames: entryInfo => {
if (entryInfo.name === 'index') {
if (entryInfo.facadeModuleId) {
const chunkName = getChunkName(entryInfo.facadeModuleId);
if (chunkName) {
return `assets/entry-${chunkName}-[name]-[hash].js`;
}
}
}
return 'assets/entry-[name]-[hash].js';
},
chunkFileNames: chunkInfo => {
if (chunkInfo.name === 'index') {
if (chunkInfo.facadeModuleId) {
const chunkName = getChunkName(chunkInfo.facadeModuleId);
if (chunkName) {
return `assets/${chunkName}-[name]-[hash].js`;
}
} else {
}
}
return 'assets/[name]-[hash].js';
},
},
plugins: [RollupNodePolyFillPlugin()],
},
},
resolve: {
preserveSymlinks: true,
alias: [
{
find: /crypto-addr-codec/,
replacement: path.resolve(
__dirname,
'node_modules',
'crypto-addr-codec',
'dist',
'index.js'
),
},
],
},
});