This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
rollup.config.js
77 lines (69 loc) · 2.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
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: 'ReactBlockUi',
entry: 'src/index.js',
plugins: [
nodeResolve(),
babel({
plugins: ['external-helpers'],
}),
commonjs(),
],
sourceMap: true,
};
}
/*
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/reactblockui.cjs.js', format: 'cjs' },
{ dest: 'dist/reactblockui.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.
Defining this config will also check that all peer dependencies are set up
correctly in the globals entry.
*/
const umdConfig = baseConfig();
umdConfig.external = peerDependencies;
umdConfig.plugins.push(replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}));
umdConfig.plugins.push(minify({ comments: false }));
umdConfig.targets = [
{ dest: 'dist/reactblockui.min.js', format: 'umd' },
];
umdConfig.globals = {
react: 'React',
'react-dom': 'ReactDOM',
};
const missingGlobals = peerDependencies.filter(dep => !(dep in umdConfig.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);
}
export default [
libConfig,
umdConfig,
];