forked from ethers-io/ethers.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup-dist.config.js
168 lines (138 loc) · 4.44 KB
/
rollup-dist.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"use strict";
// This files has a lot of overlap with rollup-pre-alias.config.js
// - should we pull some of this functionality out?
import commonjs from '@rollup/plugin-commonjs';
import resolveNode from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import sourcemaps from 'rollup-plugin-sourcemaps';
// We only need this for its version (we inject it into a require)
import elliptic from "elliptic";
function addUtilsReplace(plugins) {
// Remove the buffer check from BN.js
plugins.push(replace({
"require('buffer')": "/*RicMoo:ethers:require(buffer)*/(null)",
include: "**/lib/bn.js",
delimiters: [ '', '' ]
}));
// Remove the util from inhjerits (forces browser inherits)
plugins.push(replace({
"require('util')": "/*RicMoo:ethers:require(util)*/(null)",
include: "**/inherits/inherits.js",
delimiters: [ '', '' ]
}));
return plugins;
}
function addLangReplace(plugins) {
plugins.push(replace({
'require("./wordlists")': 'require("./browser-wordlists")/*RicMoo:ethers:require(wordlists)*/',
include: "**/wordlists/lib/index.js",
delimiters: [ '', '' ]
}));
return plugins;
}
function addEllipticReplace(plugins) {
// Replace the package.json in elliptic
plugins.push(replace({
"require('../package.json')": `/*RicMoo:ethers*/{ version: "${ elliptic.version }" }`,
include: "**/lib/elliptic.js",
delimiters: [ '', '' ]
}));
// Nuke a bunch of requires we don't need in elliptic
const thrower = "(function() { throw new Error('unsupported'); })";
const crash = "(null).crash()";
[
{ name: "./edwards", filename: "curve/index.js" },
{ name: "./mont", filename: "curve/index.js" },
{ name: "./elliptic/eddsa", filename: "lib/elliptic.js" },
{ name: "brorand", filename: "ec/index.js", text: thrower },
{ name: "brorand", filename: "lib/elliptic.js", text: thrower },
{ name: "./precomputed/secp256k1", filename: "elliptic/curves.js", text: crash },
].forEach(({ name, filename, text }) => {
if (text == null) { text = "(null)"; }
const replacement = {
include: `**/${ filename }`,
delimiters: [ '', '' ]
};
replacement[`require('${ name }')`] = `/*RicMoo:ethers:require(${ name })*/${ text }`,
plugins.push(replace(replacement));
});
return plugins;
}
function getUmdConfig() {
const plugins = [ ];
plugins.push(sourcemaps());
addUtilsReplace(plugins);
addEllipticReplace(plugins);
addLangReplace(plugins);
plugins.push(resolveNode({
mainFields: [ "browser", "main" ]
}));
plugins.push(commonjs({ }));
return {
input: `packages/ethers/lib/index.js`,
output: {
file: `packages/ethers/dist/ethers.umd.js`,
format: "umd",
name: "ethers",
sourcemap: true
},
context: "window",
treeshake: false,
plugins
};
}
function getEsmConfig() {
const plugins = [ ];
plugins.push(sourcemaps());
addUtilsReplace(plugins);
// Note: We do not need to replace the elliptic problems because they
// were addressed when aliasing (in rollup-pre-alias.config.js)
plugins.push(resolveNode({ }));
plugins.push(commonjs({ }));
return {
input: `packages/ethers/lib.esm/index.js`,
output: {
file: `packages/ethers/dist/ethers.esm.js`,
format: "esm",
sourcemap: true
},
context: "window",
treeshake: false,
plugins
};
}
/*
function getConfig() {
const plugins = [ ];
// Remove the buffer check from BN.js
plugins.push(replace({
"require('buffer')": "/ * RicMoo:ethers * /(null)",
include: "* * / lib/bn.js",
delimiters: [ '', '' ]
}));
plugins.push(resolveNode({
preferBuiltins: true
}));
plugins.push(commonjs({ }));
return {
input: `packages/ethers/lib.esm/index.js`,
output: {
file: `packages/ethers/dist/test-esm.js`,
//preserveModules: true,
format: "esm",
//name: `ethers`,
sourcemap: true,
exports: "named"
},
context: "window",
treeshake: false,
//external,
plugins
};
}
*/
const configs = [
getEsmConfig(),
getUmdConfig()
];
export default configs;