-
Notifications
You must be signed in to change notification settings - Fork 77
/
rollup.config.js
113 lines (106 loc) · 2.45 KB
/
rollup.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
import typescript from 'rollup-plugin-typescript2';
import ttypescript from 'ttypescript';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
import { visualizer } from 'rollup-plugin-visualizer';
import { terser } from 'rollup-plugin-terser';
import * as pkg from './package.json';
const external = [
...Object.keys(pkg.peerDependencies || {}),
];
const input = 'src/index.ts';
const plugins = ({ browser }) => [
typescript({
typescript: ttypescript,
tsconfig: 'tsconfig.build.json',
tsconfigOverride: {
compilerOptions: {
declaration: true,
module: 'ES2015',
},
},
}),
resolve({
browser,
dedupe: ['bn.js', 'buffer', 'crypto-hash'],
preferBuiltins: !browser,
}),
commonjs(),
json(),
];
const config = ({ browser, format } = { browser: false }) => {
const config = {
input,
plugins: plugins({ browser }),
// Default external, can be overrided
external: [
...external,
'@types/bs58',
'axios',
'bn.js',
'borsh',
'bs58',
'buffer',
'crypto-hash',
],
};
if (browser) {
switch (format) {
case 'esm':
config.output = {
file: 'lib/index.browser.esm.js',
format: 'es',
sourcemap: true,
};
break;
case 'iife':
const base = {
format: 'iife',
name: 'metaplex',
sourcemap: true,
globals: {
'@solana/web3.js': 'solanaWeb3',
'@solana/spl-token': 'splToken',
},
};
config.output = [
{
...base,
file: 'lib/index.iife.js',
},
{
...base,
file: 'lib/index.iife.min.js',
plugins: [terser(), visualizer()],
},
];
config.context = 'window';
config.external = ['@solana/web3.js', '@solana/spl-token'];
break;
default:
throw new Error(`Unknown format: ${format}`);
}
} else {
config.output = [
{
file: 'lib/index.cjs.js',
format: 'cjs',
sourcemap: true,
},
{
file: 'lib/index.esm.js',
format: 'es',
sourcemap: true,
},
];
}
return config;
};
export default [
// Node
config(),
// Browser
config({ browser: true, format: 'esm' }),
config({ browser: true, format: 'iife' }),
];