forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
83 lines (78 loc) · 1.95 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
// @flow
import babel from 'rollup-plugin-babel';
import filesize from 'rollup-plugin-filesize';
import nodeResolve from 'rollup-plugin-node-resolve';
import progress from 'rollup-plugin-progress';
import visualizer from 'rollup-plugin-visualizer';
import commonjs from 'rollup-plugin-commonjs';
import fs from 'fs';
import path from 'path';
function getComponents() {
return fs.readdirSync('./src/components').filter(filename => {
const {ext, name} = path.parse(filename);
return ext === '' && !name.startsWith('.');
});
}
function getConfig() {
return getComponents().map(component => {
const filePath = `${component}/index`;
const name = `baseui.${component}`;
return {
input: `src/components/${component}/index.js`,
...getSharedConfig({filePath, name}),
};
});
}
function getSharedConfig({filePath, name}) {
return {
output: [
{
file: `dist/${filePath}.js`,
format: 'umd',
name: name,
exports: 'named',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
sourcemap: 'inline',
},
{
file: `dist/${filePath}.es.js`,
format: 'es',
name: name,
exports: 'named',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
sourcemap: 'inline',
},
],
external: ['react', 'react-dom'],
plugins: [
progress(),
nodeResolve(),
babel({
babelrc: false,
presets: [['es2015', {modules: false}], 'stage-1', 'react'],
plugins: ['external-helpers'],
}),
visualizer(),
filesize(),
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/create-react-context/index.js': ['createReactContext'],
},
}),
],
};
}
export default [
{
input: 'src/index.js',
...getSharedConfig({filePath: 'baseui', name: 'baseui'}),
},
...getConfig(),
];