-
Notifications
You must be signed in to change notification settings - Fork 13
/
rollup.config.js
121 lines (108 loc) · 2.72 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import replacePlugin from 'rollup-plugin-replace';
import nodeResolvePlugin from 'rollup-plugin-node-resolve';
import cjsPlugin from 'rollup-plugin-commonjs';
import { terser as terserPlugin } from 'rollup-plugin-terser';
import babelPlugin from 'rollup-plugin-babel';
import path from 'path';
import { toPascalCase, toKebabCase } from 'ramda-extension';
import { keys } from 'ramda';
const { LERNA_PACKAGE_NAME, LERNA_ROOT_PATH } = process.env;
const plugins = {
cjs: cjsPlugin({
include: /node_modules/,
}),
terser: terserPlugin({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}),
nodeResolve: nodeResolvePlugin({
jsnext: true,
}),
babel: babelPlugin({
cwd: LERNA_ROOT_PATH,
runtimeHelpers: true,
}),
};
const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE = path.join(PACKAGE_ROOT_PATH, 'src/index.js');
const globals = {
'hoist-non-react-statics': 'HoistNonReactStatics',
'prop-types': 'PropTypes',
ramda: 'R',
'ramda-extension': 'R_',
react: 'React',
'react-dom': 'ReactDOM',
'react-union': 'ReactUnion',
};
// eslint-disable-next-line import/no-dynamic-require
const pkg = require(path.join(PACKAGE_ROOT_PATH, 'package.json'));
const dependencies = [...keys(pkg.dependencies), ...keys(pkg.peerDependencies)];
const external = id => dependencies.includes(id) || id.includes('@babel/runtime');
const globalName = toPascalCase(LERNA_PACKAGE_NAME);
const fileName = toKebabCase(LERNA_PACKAGE_NAME);
const umdExternal = ['react', 'react-dom', 'ramda', 'ramda-extension', 'prop-types'];
export default [
// CJS
{
input: INPUT_FILE,
external,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'lib', `${fileName}.js`),
format: 'cjs',
indent: false,
},
plugins: [plugins.babel, plugins.cjs],
},
// ES
{
input: INPUT_FILE,
external,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'es', `${fileName}.js`),
format: 'es',
indent: false,
},
plugins: [plugins.babel, plugins.cjs],
},
// UMD Development
{
input: INPUT_FILE,
external: umdExternal,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
plugins: [
plugins.nodeResolve,
replacePlugin({ 'process.env.NODE_ENV': JSON.stringify('development') }),
plugins.babel,
plugins.cjs,
],
},
// UMD Production
{
input: INPUT_FILE,
external: umdExternal,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.min.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
plugins: [
plugins.nodeResolve,
replacePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
plugins.babel,
plugins.cjs,
plugins.terser,
],
},
];