-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.es.js
62 lines (49 loc) · 1.24 KB
/
rollup.config.es.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
import path from 'path';
import { readFileSync } from 'fs';
import commonConf from './rollup.common';
const OUTPUT_NAME = 'library';
const chunkArray = readFileSync('./src/index.js', 'utf8')
.split('\n') // -> all lines
.filter(line => line.includes(' from ')) // -> lines which export something
.map(line => {
console.log(`src/${/.* from ('|")(\.\/|~)?(.*)('|").*/g.exec(line)[3]}`);
return `src/${/.* from ('|")(\.\/|~)?(.*)('|").*/g.exec(line)[3]}`;
}); // -> module paths
const input = {
index: 'src/index.js'
};
chunkArray.forEach(path => {
const name = path // 'yolo/FooBar'
.split('/');
const nameArray = name[name.length - 1] === 'src' ? name[name.length - 2] : name[name.length - 1];
const result = nameArray.replace(/^\w/, c => c.toLowerCase());
console.log(result);
input[result] = path;
});
console.log(input);
const GLOBALS = {
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
events: 'events',
string_decoder: 'string_decoder',
buffer: 'buffer',
path: 'path'
};
const OUTPUT_DATA = [
{
dir: 'dist/es',
format: 'es'
}
];
const config = OUTPUT_DATA.map(({ dir, format }) => ({
input,
output: {
dir,
format,
name: OUTPUT_NAME,
globals: GLOBALS
},
...commonConf
}));
export default config;