forked from web3/web3.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
106 lines (99 loc) · 2.8 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
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import autoExternal from 'rollup-plugin-auto-external';
import cleanup from 'rollup-plugin-cleanup';
const config = [
{
input: 'src/index.js',
output: [
{
file: '',
format: 'cjs'
},
{
name: '',
file: '',
format: 'umd',
globals: {}
}
],
plugins: [
babel({
exclude: 'node_modules/**',
babelrc: false,
runtimeHelpers: true,
presets: [
[
'@babel/env',
{
modules: false,
targets: {
node: '8',
browsers: 'last 2 versions'
}
}
]
],
plugins: [
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
['@babel/plugin-transform-runtime', {
'helpers': true,
'regenerator': true
}]
]
}),
json(),
autoExternal(),
cleanup()
]
}
];
/**
* Returns the rollup configuration with globals and names set.
*
* @param {String} name
* @param {String} outputFileName
* @param {Object} globals
* @param {Boolean} ignoreEsm
*
* @returns {Array}
*/
export default (name, outputFileName, globals, ignoreEsm) => {
// CJS
config[0].output[0].file = 'dist/' + outputFileName + '.cjs.js';
// UMD
config[0].output[1].name = name;
config[0].output[1].file = 'dist/' + outputFileName + '.umd.js';
config[0].output[1].globals = globals;
if (!ignoreEsm) {
config[1] = {
input: 'src/index.js',
output: [
{
file: 'dist/' + outputFileName + '.esm.js',
format: 'es'
}
],
plugins: [
babel({
exclude: 'node_modules/**',
plugins: [
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from'
]
}),
json(),
autoExternal(),
cleanup()
]
};
if (name === 'Web3') {
config[1].input = 'src/Web3.js';
}
}
if (name === 'Web3') {
config[0].input = 'src/Web3.js';
}
return config;
};