forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
152 lines (128 loc) · 4.33 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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);
dependencies.push('react-transition-group/Transition');
function globals() {
return {
react: 'React',
'react-dom': 'ReactDOM',
};
}
function baseConfig() {
return {
input: 'src/index.js',
plugins: [
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
babel({
babelrc: false,
presets: [
[
'@babel/env',
{
loose: true,
shippedProposals: true,
modules: false,
targets: {
ie: 9
}
}
],
'@babel/react'
],
plugins: ['@babel/plugin-proposal-export-default-from', '@babel/plugin-proposal-export-namespace-from']
}),
]
};
}
function baseUmdConfig(minified) {
const config = Object.assign(baseConfig(), {
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.output = [
{ sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.cjs.js', format: 'cjs' },
{ sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.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 input.
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.output = [
{ globals: globals(), sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.full.js', format: 'umd' },
];
// Validate globals in main UMD config
const missingGlobals = peerDependencies.filter(dep => !(dep in 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.output = [
{ globals: globals(), sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.full.min.js', format: 'umd' },
];
const external = umdFullConfig.external.slice();
external.push('react-transition-group/Transition');
external.push('react-popper');
const allGlobals = Object.assign({}, globals(), {
'react-popper': 'ReactPopper',
'react-transition-group/Transition': 'ReactTransitionGroup.Transition',
});
const umdConfig = baseUmdConfig(false);
umdConfig.external = external;
umdConfig.output = [
{ globals: allGlobals, sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.js', format: 'umd' },
];
const umdConfigMin = baseUmdConfig(true);
umdConfigMin.external = external;
umdConfigMin.output = [
{ globals: allGlobals, sourcemap: true, name: 'Reactstrap', file: 'dist/reactstrap.min.js', format: 'umd' },
];
export default [
libConfig,
umdFullConfig,
umdFullConfigMin,
umdConfig,
umdConfigMin,
];