-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrollup.config.js
100 lines (90 loc) · 2.7 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
import path from 'path';
import autoExternal from 'rollup-plugin-auto-external';
import replace from 'rollup-plugin-replace';
import * as plugins from './rollup/plugins';
import { getGlobalName, getFileName } from './rollup/utils';
const { LERNA_PACKAGE_NAME } = process.env;
const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE = path.join(PACKAGE_ROOT_PATH, 'src/index.js');
// NOTE: Packages which are meant to be "plug and play" for prototyping using unpkg.
const presets = ['@redux-tools/react'];
// NOTE: Only add globals which must be loaded manually when prototyping with a preset.
const globals = {
react: 'React',
'react-dom': 'ReactDOM',
'react-redux': 'ReactRedux',
redux: 'Redux',
};
const globalName = getGlobalName(LERNA_PACKAGE_NAME);
const fileName = getFileName(LERNA_PACKAGE_NAME);
export default [
// NOTE: CJS
{
input: INPUT_FILE,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'lib', `${fileName}.js`),
format: 'cjs',
indent: false,
},
// HACK: Necessary, because `autoExternal` plugin does not handle deep imports.
// https://github.com/stevenbenisek/rollup-plugin-auto-external/issues/7
external: ['rxjs/operators'],
plugins: [autoExternal(), plugins.nodeResolve, plugins.babel, plugins.cjs],
},
// NOTE: ES
{
input: INPUT_FILE,
output: {
file: path.join(PACKAGE_ROOT_PATH, 'es', `${fileName}.js`),
format: 'es',
indent: false,
},
// HACK: Necessary, because `autoExternal` plugin does not handle deep imports.
// https://github.com/stevenbenisek/rollup-plugin-auto-external/issues/7
external: ['rxjs/operators'],
plugins: [autoExternal(), plugins.nodeResolve, plugins.babel, plugins.cjs],
},
// NOTE: Only build UMD for the presets.
// The individual packages are not meant to be used with UMD.
...(presets.includes(LERNA_PACKAGE_NAME)
? [
// NOTE: UMD Development
{
input: INPUT_FILE,
external: Object.keys(globals),
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
plugins: [
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
plugins.nodeResolve,
plugins.babel,
plugins.cjs,
],
},
// NOTE: UMD Production
{
input: INPUT_FILE,
external: Object.keys(globals),
output: {
file: path.join(PACKAGE_ROOT_PATH, 'dist', `${fileName}.min.js`),
format: 'umd',
name: globalName,
indent: false,
globals,
},
plugins: [
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
plugins.nodeResolve,
plugins.babel,
plugins.cjs,
plugins.terser,
],
},
]
: []),
];