-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.js
87 lines (82 loc) · 2.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
import { defineConfig } from 'vite';
import path from 'path';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import StringReplace from 'vite-plugin-string-replace';
import dts from 'vite-plugin-dts';
import commonjs from '@rollup/plugin-commonjs';
export default defineConfig(({ mode }) => {
const format = process.env.BUILD_FORMAT || 'es';
const outputDir = format === 'umd' ? 'dist/umd' : 'dist/es';
const isEsm = format === 'es';
// ESM does not bundle these to add flexibility e.g. for NextJS Apps.
const externalDependencies = [
...(isEsm ? [] : ['@hashgraph/hedera-wallet-connect']),
'@hashgraph/proto',
'@hashgraph/sdk',
'@walletconnect/modal',
'@walletconnect/core',
'@walletconnect/modal-core',
'@walletconnect/qrcode-modal',
'@walletconnect/utils',
'fetch-retry',
];
const plugins = [
nodePolyfills(),
StringReplace([
{
search: 'VITE_BUILD_FORMAT',
replace: format,
},
]),
dts({
insertTypesEntry: true,
include: ['src/**/*.ts'],
outputDir: outputDir,
}),
];
// Only add commonjs plugin for ESM build
if (isEsm) {
plugins.push(
commonjs({
include: /node_modules\/@hashgraph\/hedera-wallet-connect/,
})
);
}
return {
plugins,
build: {
outDir: outputDir,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'HashinalsWalletConnectSDK',
fileName: (format) => `hashinal-wc.${format}.js`,
formats: [format],
},
rollupOptions: {
external: format === 'es' ? externalDependencies : [],
output: {
globals: (id) => id,
},
},
commonjsOptions: {
include: [/node_modules/],
},
minify: 'terser',
sourcemap: true,
},
define: {
VITE_BUILD_FORMAT: JSON.stringify(format),
},
resolve: {
alias: {
process: 'process/browser',
stream: 'stream-browserify',
zlib: 'browserify-zlib',
util: 'util',
},
},
ssr: {
external: externalDependencies,
},
};
});