-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathvite.config.mts
More file actions
109 lines (104 loc) · 2.99 KB
/
vite.config.mts
File metadata and controls
109 lines (104 loc) · 2.99 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
import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
const DEFAULT_VITE_DEV_PORT = 3002
export default defineConfig(({ mode }) => {
const isProd = mode === 'production'
const isComponentBuild = process.env.BUILD_MODE === 'component'
if (isComponentBuild) {
return {
build: {
lib: {
entry: path.resolve(__dirname, 'src/App.tsx'),
name: 'beeDashboard',
fileName: format => `App.${format === 'es' ? 'js' : 'cjs.js'}`,
formats: ['es', 'cjs'],
},
sourcemap: !isProd,
minify: false,
outDir: 'lib',
rollupOptions: {
external: ['react', 'react-dom'],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
assetFileNames: (assetInfo: any) => {
if (assetInfo.originalFileNames?.includes('style.css') || assetInfo.names?.includes('bee-dashboard.css'))
return 'App.css'
return assetInfo.names?.[0] || 'asset'
},
},
},
},
plugins: [
react(),
dts({
exclude: ['**/tests/**', 'src/index.tsx'],
outDir: 'lib',
entryRoot: 'src',
tsconfigPath: './tsconfig.lib.json',
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.scss'],
},
}
}
return {
plugins: [
react(),
nodePolyfills({
include: ['util', 'buffer'],
globals: {
Buffer: true,
global: true,
process: true,
},
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.scss'],
},
optimizeDeps: {
// include: [],
// exclude: [], // add libs for local development, if needed, e.g.: @solarpunkltd/file-manager-lib
},
build: {
outDir: 'build',
sourcemap: !isProd,
commonjsOptions: {
transformMixedEsModules: true,
},
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
if (id.includes('react') || id.includes('react-dom') || id.includes('@mui') || id.includes('@emotion'))
return 'vendor-react-mui'
if (id.includes('ethers') || id.includes('@ethersproject')) return 'vendor-ethers'
if (id.includes('@ethersphere/bee-js')) return 'vendor-bee-js'
if (id.includes('notistack')) return 'vendor-notistack'
// let Vite handle the rest
}
},
},
},
},
server: {
port: DEFAULT_VITE_DEV_PORT,
open: true,
},
publicDir: 'public',
assetsInclude: ['**/*.svg'],
}
})