forked from TrustlessComputer/bvm-website-sats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
125 lines (122 loc) · 3.09 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
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
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import { createHtmlPlugin } from 'vite-plugin-html';
import checker from 'vite-plugin-checker';
import path from 'path';
import macrosPlugin from 'vite-plugin-babel-macros';
import { visualizer } from 'rollup-plugin-visualizer';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import inject from '@rollup/plugin-inject';
import { dependencies } from './package.json';
function renderChunks(deps) {
let chunks = {};
Object.keys(deps).forEach(key => {
if (['react', 'react-router-dom', 'react-dom', 'lodash', 'bootstrap', 'axios'].includes(key)) return;
chunks[key] = [key];
});
return chunks;
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'REACT_');
return {
server: { hmr: true, port: 6009 },
plugins: [
visualizer({
template: 'treemap', // or sunburst
open: false,
gzipSize: true,
brotliSize: true,
filename: 'analice.html',
}),
macrosPlugin(),
react({
include: ['**/*.tsx', '**/*.ts'],
babel: {
plugins: [
[
'babel-plugin-styled-components',
{
displayName: true,
fileName: false,
},
],
],
},
}),
tsconfigPaths(),
createHtmlPlugin({
minify: true,
inject: {
data: {
...env,
MODE: mode,
},
},
}),
checker({ typescript: true }),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src/'),
stream: 'stream-browserify',
buffer: 'buffer',
},
},
css: {
postcss: ctx => ({
parser: ctx.parser ? 'sugarss' : false,
map: ctx.env === 'development' ? ctx.map : false,
plugins: {
'postcss-import': {},
'postcss-nested': {},
cssnano: ctx.env === 'production' ? {} : false,
autoprefixer: { overrideBrowserslist: ['defaults'] },
},
}),
},
define: {
'process.env.NODE_DEBUG': JSON.stringify(''),
DOT_ENV: env,
__CLIENT__: true,
},
build: {
target: ['esnext'],
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-router-dom', 'react-dom'],
...renderChunks(dependencies),
},
},
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
},
commonjsOptions: {
transformMixedEsModules: true,
},
},
test: {
globals: true,
coverage: {
reporter: ['text', 'json', 'html'],
},
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
define: {
global: 'globalThis',
},
supported: {
bigint: true,
},
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
],
},
};
});