-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.common.js
76 lines (68 loc) · 1.86 KB
/
rollup.config.common.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
import fs from 'fs';
import path from 'path';
import minimatch from 'minimatch';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
const ROOT_RESOLVE = path.resolve();
const PACKAGES_RESOLVE = path.resolve('packages');
const ALL_PACKAGES = '*';
const EXCLUDES = ['react-cache'];
let INCLUDES = [];
if (process.env.PACKAGES) {
INCLUDES = process.env.PACKAGES.split(/\s*,\s*/).filter(pattern => {
if (pattern.startsWith('!')) {
EXCLUDES.push(pattern.substring(1));
return false;
}
return true;
});
if (EXCLUDES.length > 0 && INCLUDES.length === 0) {
INCLUDES = [ALL_PACKAGES];
}
}
const config = {
input: path.resolve(ROOT_RESOLVE, 'src', 'index.js'),
plugins: [
resolve(),
commonjs({
include: 'node_modules/**',
}),
babel({
exclude: 'node_modules/**',
}),
],
external: [
'planck-js',
'stage-js/platform/web',
'react',
'react-dom',
'react-is',
'styled-components',
],
};
export const configs = Object.entries(
(fs.existsSync(PACKAGES_RESOLVE)
? fs.readdirSync(PACKAGES_RESOLVE)
: []
).reduce((collection, name) => {
const pathname = path.resolve(PACKAGES_RESOLVE, name);
if (fs.statSync(pathname).isDirectory()
&& (INCLUDES.some(pattern => minimatch(pathname, `${PACKAGES_RESOLVE}/${pattern}`))
&& !EXCLUDES.some(pattern => minimatch(pathname, `${PACKAGES_RESOLVE}/${pattern}`)))) {
return {
...collection,
[pathname]: {
...config,
input: path.resolve(PACKAGES_RESOLVE, name, 'src', 'index.js'),
},
};
}
return collection;
}, {}),
);
if ((INCLUDES.length === 0 || INCLUDES.includes(ALL_PACKAGES))
&& fs.statSync(config.input).isFile()) {
configs.push([ROOT_RESOLVE, config]);
}
export default config;