This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
forked from medipass/react-payment-inputs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
95 lines (86 loc) · 2.13 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
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const proxyDirectories = require('rollup-plugin-proxy-directories');
const { terser } = require('rollup-plugin-terser');
const pkg = require('./package.json');
const extensions = ['.js', '.jsx', '.json'];
const makeExternalPredicate = externalArr => {
if (!externalArr.length) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return id => pattern.test(id);
};
const getExternal = (umd, pkg) => {
const external = [...Object.keys(pkg.peerDependencies), 'prop-types'];
const allExternal = [...external, ...Object.keys(pkg.dependencies)];
return makeExternalPredicate(umd ? external : allExternal);
};
const commonPlugins = [
babel({
extensions,
exclude: ['node_modules/**']
}),
resolve({ extensions, preferBuiltins: false })
];
const getPlugins = umd =>
umd
? [
...commonPlugins,
commonjs({
include: /node_modules/
}),
terser()
]
: commonPlugins;
const getOutput = (umd, pkg) =>
umd
? {
name: 'ReactPaymentInputs',
file: pkg.unpkg,
format: 'umd',
exports: 'named',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
'styled-components': 'StyledComponents'
}
}
: [
{
file: pkg.main,
format: 'cjs',
exports: 'named'
},
{
file: pkg.module,
format: 'es'
}
];
const createConfig = ({ umd, pkg, plugins = [], ...config }) => ({
external: getExternal(umd, pkg),
plugins: [...getPlugins(umd), ...plugins],
output: getOutput(umd, pkg),
...config
});
export default [
createConfig({
pkg,
input: [],
output: [
{
format: 'es',
dir: 'es'
},
{
format: 'cjs',
dir: 'lib',
exports: 'named'
}
],
plugins: [proxyDirectories()]
}),
createConfig({ pkg, input: 'src/index.js', umd: true })
];