-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.config.js
101 lines (96 loc) · 2.92 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
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { nodeResolve } from '@rollup/plugin-node-resolve';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import tsconfigPaths from 'vite-tsconfig-paths';
function replaceBytecodePlugin() {
return {
name: 'replace-bytecode-plugin',
// Hook into the transform process to modify the code
transform(code, id) {
if (!id.includes('@subql/contract-sdk')) return;
// Apply transformation only to JavaScript/TypeScript files
if (!id.endsWith('.js') && !id.endsWith('.ts')) return;
// Replace `const _bytecode = "0x..."` with `const _bytecode = "0"`
const transformedCode = code.replace(/const\s+_bytecode\s*=\s*"0x[0-9a-fA-F]+"/g, 'const _bytecode = "0"');
return {
code: transformedCode,
map: null, // Skip source maps for simplicity; add if needed
};
},
};
}
export default defineConfig({
plugins: [
react(),
nodePolyfills({
exclude: ['buffer'],
}),
tsconfigPaths(),
...(process.env.analyze ? [visualizer()] : []),
replaceBytecodePlugin(),
],
server: {
port: 3006,
},
resolve: {
mainFields: [],
},
css: {
preprocessorOptions: {
less: {
modifyVars: { '@primary-color': '#1677ff', '@text-color': '#454f58', '@text-color-secondary': '#919eab' },
javascriptEnabled: true,
additionalData: '@root-entry-name: default;',
},
},
modules: {
localIdentName: '[local]_[hash:base64:5]',
},
},
build: {
minify: true,
sourcemap: false,
rollupOptions: {
cache: false,
output: {
compact: true,
sourcemap: false,
manualChunks: {
lodash: ['lodash'],
antd: ['antd'],
'@sentry': ['@sentry/react'],
axios: ['axios'],
echarts: [
'echarts',
'echarts/charts',
'echarts/components',
'echarts/core',
'echarts/renderers',
'echarts-for-react/lib/core',
],
dayjs: ['dayjs'],
'@subql/contract-sdk': ['@subql/contract-sdk'],
'@subql/components': ['@subql/components'],
'@subql/network-clients': ['@subql/network-clients'],
'@subql/network-config': ['@subql/network-config'],
'@subql/network-query': ['@subql/network-query'],
'@subql/react-hooks': ['@subql/react-hooks'],
'react-countdown': ['react-countdown'],
ahooks: ['ahooks'],
'@ant-design/icons': ['@ant-design/icons'],
localforage: ['localforage'],
'@web3-name-sdk': ['@web3-name-sdk/core'],
},
},
plugins: [
nodeResolve({
dedupe: ['lodash', 'lodash-es'],
}),
],
},
},
});