-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
228 lines (200 loc) · 5.2 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import replace from '@rollup/plugin-replace';
import { terser as minify } from 'rollup-plugin-terser';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import image from '@rollup/plugin-image';
import postcss from 'rollup-plugin-postcss';
import typescript from 'rollup-plugin-typescript2';
const hash = '[name]_[local]__[hash:base64:5]';
const peerDependencies = ["react", "react-dom"];
const dependencies = ["@babel/runtime", "classnames", "lodash.throttle", "prop-types","redux"];
process.NODE_ENV = 'production';
function globals() {
return {
react: 'React',
'react-dom': 'ReactDOM'
};
}
function baseConfig(minimize = false) {
return {
input: 'src/components/video/index.tsx',
output: {},
plugins: [
// scss({
// output: 'lib/index.css'
// }),
postcss({
minimize,
extract: true,
modules: true,
sourceMap: false,
}),
image(),
nodeResolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
commonjs({
include: ['node_modules/**']
}),
babel({
babelrc: false,
babelHelpers: 'runtime',
extensions: ['.js', '.jsx', '.ts', '.tsx'],
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"browsers": [
"edge>= 17",
"firefox>= 60",
"chrome>= 40",
"safari>= 10",
],
"node": "6.10"
},
}
],
"@babel/preset-react",
"@babel/preset-typescript",
],
plugins: [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-object-rest-spread",
[
"react-css-modules",
{
generateScopedName: hash,
webpackHotModuleReloading: false,
handleMissingStyleName: "warn",
filetypes: {
".scss": {
syntax: "postcss-scss"
}
}
}
]
]
}),
]
};
}
function baseUmdConfig(minified) {
const config = Object.assign(baseConfig(minified), {
external: peerDependencies
});
config.plugins.push(
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
);
if (minified) {
config.plugins.push(minify());
}
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: 'index',
file: 'lib/index.cjs.js',
format: 'cjs'
},
{
sourcemap: true,
name: 'index',
file: 'lib/index.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.
index has two versions:
1) `index.min.js`
This file excludes `redux` from
the lib build where they need to be manually required if any
application uses components that require these features.
2) `index.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: 'index',
file: 'lib/index.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: 'index',
file: 'lib/index.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: 'index',
file: 'lib/index.js',
format: 'umd'
}
];
const umdConfigMin = baseUmdConfig(true);
umdConfigMin.external = external;
umdConfigMin.output = [
{
globals: allGlobals,
sourcemap: true,
name: 'index',
file: 'lib/index.min.js',
format: 'umd'
}
];
export default [
// libConfig,
umdConfig,
umdConfigMin
];