This repository was archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrollup.config.js
More file actions
204 lines (190 loc) · 5.82 KB
/
rollup.config.js
File metadata and controls
204 lines (190 loc) · 5.82 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* We build three flavors of Bitcoin Source:
*
* 1. 'common' - ES5 CommonJS build for use in node applications. Dependencies are external.
* 2. 'esm' - ES6 imports build for use in other builds. Dependencies are external.
* 3. 'browser' - ES5 build for use in a browser. Dependencies are bundled.
*
* Each also has a minified version meant for distribution. We do not build sourcemaps. If
* developers need them for debugging, they may turn them on with the sourcemap option which
* must be enabled at the top level and in terser for minified builds.
*/
import babel from 'rollup-plugin-babel'
import builtins from 'rollup-plugin-node-builtins'
import commonjs from 'rollup-plugin-commonjs'
import flow from 'rollup-plugin-flow'
import globals from 'rollup-plugin-node-globals'
import json from 'rollup-plugin-json'
import resolve from 'rollup-plugin-node-resolve'
import pkg from './package.json'
import { terser } from 'rollup-plugin-terser'
// The text to appear at the top of the generated files.
const license = `/**
* https://github.com/the-bitcoin-token/bitcoin-source
* Copyright (c) 2019 Bitcoin Computer
* Copyright (c) 2019 Brenton Gunning
* Copyright (c) 2018 Janez Urevc
* Copyright (c) 2018-2019 Clemens Ley
* Copyright (c) 2017-2018 Emilio Almansi
* Copyright (c) 2013-2017 BitPay, Inc.
* Copyright (c) 2009-2015 The Bitcoin Core developers
* Copyright (c) 2014 Ryan X. Charles
* Copyright (c) 2014 reddit, Inc.
* Copyright (c) 2011 Stefan Thomas <justmoon@members.fsf.org>
* Copyright (c) 2011 Google Inc.
* Distributed under the MIT software license, see the accompanying
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.
*/`
// Disable circular dependency warnings in our library because they are allowed in ES6 and don't
// cause problems for us. The maintainer of Rollup does not plan to remove this warning. This is
// his recommendation. See: https://github.com/rollup/rollup/issues/2271
function onwarnHook(warning, rollupWarn) {
// Imports from files are OK and do not cause problems
const exceptions = [
'src/address.js',
'src/hdprivatekey.js',
'src/publickey.js',
'src/transaction/transaction.js',
'src/transaction/input/input.js',
]
if (exceptions.indexOf(warning.importer) === -1) {
rollupWarn(warning)
}
}
// Define the libraries that bitcoin-source is dependant on so that we don't bundle them
const nodeDependencies = ['assert', 'url']
const packageDependencies = Object.keys(pkg.dependencies)
const dependencies = nodeDependencies.concat(packageDependencies)
// Define our default babel plugin config
const babelPluginConfig = {
// Prefer the config below over babelrc
babelrc: false,
presets: [
// Disable converting modules because rollup will do this better
['@babel/preset-env', { targets: { esmodules: true } }],
],
}
// Define our babel plugin config when generating minified builds
const babelPluginMinifiedConfig = {
// Prefer the config below over babelrc
babelrc: false,
presets: [
// Disable converting modules because rollup will do this better
['@babel/preset-env', { targets: { esmodules: true } }],
[
'minify',
{
// Don't minify the built-in objects. This breaks for some reason.
builtIns: false,
// Our terser will mangle names and this breaks for some reason
mangle: false,
},
],
],
}
const common = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.common.js`,
format: 'cjs',
banner: license,
},
external: dependencies,
onwarn: onwarnHook,
plugins: [
// Strip out flow types first before any other processing
flow(),
// Support importing json files, including package.json for versioning
json(),
// Use the node module resolution algorithm
resolve(),
babel(babelPluginConfig),
],
}
const commonMin = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.common.min.js`,
format: 'cjs',
banner: license,
// Minify code generated by rollup
compact: true,
},
external: dependencies,
onwarn: onwarnHook,
plugins: [
flow(),
json(),
resolve(),
babel(babelPluginMinifiedConfig),
// Minify the resulting code
terser(),
],
}
const esm = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.esm.js`,
format: 'es',
banner: license,
},
external: dependencies,
onwarn: onwarnHook,
plugins: [flow(), json(), resolve(), babel(babelPluginConfig)],
}
const esmMin = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.esm.min.js`,
format: 'es',
banner: license,
compact: true,
},
external: dependencies,
onwarn: onwarnHook,
plugins: [flow(), json(), resolve(), babel(babelPluginMinifiedConfig), terser()],
}
const browser = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.browser.js`,
format: 'iife',
name: 'Bitcoin',
banner: license,
},
onwarn: onwarnHook,
plugins: [
flow(),
json(),
// Parse require() statements in any dependencies. Any non-commonjs modules will be ignored,
// so we can run this across all dependencies, but bitcoin source files must use ES6 imports.
// We prefer builtins like util over our own util.
commonjs({ preferBuiltins: true }),
resolve({ browser: true, preferBuiltins: true }),
globals(),
builtins(),
babel(babelPluginConfig),
],
}
const browserMin = {
input: 'src/index.js',
output: {
file: `dist/${pkg.name}.browser.min.js`,
format: 'iife',
name: 'Bitcoin',
banner: license,
compact: true,
},
onwarn: onwarnHook,
plugins: [
flow(),
json(),
commonjs({ preferBuiltins: true }),
resolve({ browser: true, preferBuiltins: true }),
globals(),
builtins(),
babel(babelPluginMinifiedConfig),
terser(),
],
}
export default [common, commonMin, esm, esmMin, browser, browserMin]