forked from video-react/video-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
189 lines (166 loc) · 4.24 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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';
import sass from 'rollup-plugin-sass';
// Require understands JSON files.
const packageJson = require('./package.json');
const peerDependencies = Object.keys(packageJson.peerDependencies);
const dependencies = Object.keys(packageJson.dependencies);
function globals() {
return {
react: 'React',
'react-dom': 'ReactDOM'
};
}
function baseConfig() {
return {
input: 'src/video-react.js',
plugins: [
sass({
output: 'dist/video-react.css'
}),
nodeResolve(),
commonjs({
include: 'node_modules/**'
}),
babel({
babelrc: false,
presets: [
[
'@babel/env',
{
loose: true,
shippedProposals: true,
modules: false,
targets: {
ie: 9
}
}
],
'@babel/react'
]
})
]
};
}
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: 'video-react',
file: 'dist/video-react.cjs.js',
format: 'cjs'
},
{
sourcemap: true,
name: 'video-react',
file: 'dist/video-react.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.
video-react has two versions:
1) `video-react.min.js`
This file excludes `redux` from
the dist build where they need to be manually required if any
application uses components that require these features.
2) `video-react.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: 'video-react',
file: 'dist/video-react.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: 'video-react',
file: 'dist/video-react.full.min.js',
format: 'umd'
}
];
const external = umdFullConfig.external.slice();
external.push('redux');
const allGlobals = Object.assign({}, globals(), {
redux: 'Redux'
});
const umdConfig = baseUmdConfig(false);
umdConfig.external = external;
umdConfig.output = [
{
globals: allGlobals,
sourcemap: true,
name: 'video-react',
file: 'dist/video-react.js',
format: 'umd'
}
];
const umdConfigMin = baseUmdConfig(true);
umdConfigMin.external = external;
umdConfigMin.output = [
{
globals: allGlobals,
sourcemap: true,
name: 'video-react',
file: 'dist/video-react.min.js',
format: 'umd'
}
];
export default [
libConfig,
umdFullConfig,
umdFullConfigMin,
umdConfig,
umdConfigMin
];