-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
137 lines (114 loc) · 3.75 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import minify from 'rollup-plugin-babel-minify';
import replace from 'rollup-plugin-replace';
// Require understands JSON files.
const packageJson = require('./package.json');
const peerDependencies = Object.keys(packageJson.peerDependencies);
const dependencies = Object.keys(packageJson.dependencies);
function baseConfig() {
return {
moduleName: 'react-mobileui',
entry: 'src/index.js',
plugins: [
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
babel({
plugins: ['external-helpers'],
}),
],
sourceMap: true,
};
}
function baseUmdConfig(minified) {
const config = Object.assign(baseConfig(), {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
external: peerDependencies,
});
config.plugins.push(replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}));
if (minified) {
config.plugins.push(minify({ comments: false }));
}
return config;
}
/*
COMMONJS / MODULE CONFIG
------------------------
Goal of this configuration is to generate bundles to be consumed by bundlers.
This configuration is not minimized and will import all dependencies.
*/
const libConfig = baseConfig();
// Do not include any of the dependencies
libConfig.external = peerDependencies.concat(dependencies);
libConfig.targets = [
{ dest: 'dist/react-mobileui.cjs.js', format: 'cjs' },
{ dest: 'dist/react-mobileui.es.js', format: 'es' },
];
/*
UMD CONFIG
----------
Goal of this configuration is to be directly included on web pages.
This configuration is minimized and will include dependencies that are not
marked as peer dependencies. ** See below
Defining this config will also check that all peer dependencies are set up
correctly in the globals entry.
Reactstrap has two versions:
1) `reactstrap.min.js`
This file excludes `react-popper` and `react-transition-group` from
the dist build where they need to be manually required if any
application uses components that require these features.
2) `reactstrap.full.min.js`
This file includes all dependencies.
For both versions the peer dependencies are always excluded and must be manually
included - `react` and `react-dom`.
*/
const umdFullConfig = baseUmdConfig(false);
umdFullConfig.targets = [
{ dest: 'dist/react-mobileui.full.js', format: 'umd' },
];
// Validate globals in main UMD config
const missingGlobals = peerDependencies.filter(dep => !(dep in umdFullConfig.globals));
if (missingGlobals.length) {
console.error('All peer dependencies need to be mentioned in globals, please update rollup.config.js.');
console.error('Missing: ' + missingGlobals.join(', '));
console.error('Aborting build.');
process.exit(1);
}
const umdFullConfigMin = baseUmdConfig(true);
umdFullConfigMin.targets = [
{ dest: 'dist/react-mobileui.full.min.js', format: 'umd' },
];
const external = umdFullConfig.external.slice();
external.push('react-transition-group/Transition');
external.push('react-popper');
const globals = Object.assign({}, umdFullConfig.globals, {
'react-popper': 'ReactPopper',
'react-transition-group/Transition': 'ReactTransitionGroup.Transition',
});
const umdConfig = baseUmdConfig(false);
umdConfig.external = external;
umdConfig.globals = globals;
umdConfig.targets = [
{ dest: 'dist/react-mobileui.js', format: 'umd' },
];
const umdConfigMin = baseUmdConfig(true);
umdConfigMin.external = external;
umdConfigMin.globals = globals;
umdConfigMin.targets = [
{ dest: 'dist/react-mobileui.min.js', format: 'umd' },
];
export default [
libConfig,
umdFullConfig,
umdFullConfigMin,
umdConfig,
umdConfigMin,
];