-
Notifications
You must be signed in to change notification settings - Fork 10
/
rollup.config.common.mjs
88 lines (76 loc) · 2.1 KB
/
rollup.config.common.mjs
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
import fs from 'fs';
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import { babel } from '@rollup/plugin-babel';
import mjsEntry from 'rollup-plugin-mjs-entry';
import flowEntry from 'rollup-plugin-flow-entry';
import { rootResolve } from './shared/utils.js';
import { setup, getProjects, getPackageName, getIncludes } from './workspaces.js';
await (setup());
const ROOT_RESOLVE = rootResolve();
const projects = await (getProjects());
const paths = [];
let exportConditions = [];
if (['development', 'test'].some(env => env === process.env.BABEL_ENV)) {
exportConditions = ['development'];
}
let packages = [];
projects.forEach((project, cwd) => {
paths.push(cwd);
packages.push(getPackageName(cwd));
});
packages = await (Promise.all(packages));
export const output = ({ dir, format, suffix = '', ...options }) => {
const extension = format === 'es' ? '.js' : '.cjs';
return {
dir,
entryFileNames: `[name]${suffix}${extension}`,
chunkFileNames: `[name]-[hash]${suffix}${extension}`,
format,
exports: 'auto',
sourcemap: 'inline',
...options,
};
};
const config = {
input: path.resolve(ROOT_RESOLVE, 'src', 'index.js'),
plugins: [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.BABEL_ENV || 'production'),
},
}),
resolve({
exportConditions,
}),
commonjs({
include: /(node_modules|.yarn)/,
}),
flowEntry(),
babel({
exclude: /(node_modules|.yarn)/,
babelHelpers: 'bundled',
configFile: path.resolve(ROOT_RESOLVE, './babel.config.js'),
}),
mjsEntry({ includeDefault: true }),
],
external: [
...packages,
'react',
'react-dom',
'styled-components',
],
};
export const configs = getIncludes().length === 0 && fs.statSync(config.input).isFile()
? [ROOT_RESOLVE, config]
: paths.map(cwd => [
cwd,
{
...config,
input: path.resolve(cwd, 'src', 'index.js'),
},
]);
export default config;