-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
91 lines (87 loc) · 2.87 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
/* eslint-disable flowtype-errors/show-errors, no-console, import/extensions */
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import commonjs from 'rollup-plugin-commonjs';
import inject from 'rollup-plugin-inject';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import cleanup from 'rollup-plugin-cleanup';
import visualizer from 'rollup-plugin-visualizer';
import builtins from 'rollup-plugin-node-builtins';
import pkg from './package.json';
import declination from './declination.json';
const processShim = '\0process-shim';
const prod = process.env.PRODUCTION;
const mode = prod ? 'production' : 'development';
const { external, globals } = declination;
console.log(`Creating ${mode} bundle...`);
const output = prod ? [
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.min.js`, format: 'umd', sourcemap: true,
},
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.cjs.min.js`, format: 'cjs', sourcemap: true,
},
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.esm.js`, format: 'es', sourcemap: true,
},
] : [
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.js`, format: 'umd', sourcemap: true,
},
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.cjs.js`, format: 'cjs', sourcemap: true,
},
{
name: pkg.name, exports: 'named', globals, file: `dist/${pkg.name}.esm.js`, format: 'es', sourcemap: true,
},
];
const plugins = [
// Unlike Webpack and Browserify, Rollup doesn't automatically shim Node
// builtins like `process`. This ad-hoc plugin creates a 'virtual module'
// which includes a shim containing just the parts the bundle needs.
{
resolveId(importee) {
if (importee === processShim) return importee;
return null;
},
load(id) {
if (id === processShim) return 'export default { argv: [], env: {} }';
return null;
},
},
builtins(),
nodeResolve({
browser: true,
}),
commonjs({
include: 'node_modules/**',
namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
'@bootstrap-styled/utils': ['parseTransition'],
immutable: ['fromJS'],
'react-is': ['isElement', 'isValidElementType', 'ForwardRef'],
},
}),
replace({
'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
}),
inject({
process: processShim,
}),
json(),
babel({
babelrc: false,
exclude: 'node_modules/**',
}),
cleanup(),
];
export default output.map((o) => ({
input: 'src/index.js',
external,
output: o,
plugins: prod ? plugins.concat([terser(), visualizer({ filename: './bundle-stats.html' })]) : plugins,
}));