forked from diegomura/react-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
130 lines (119 loc) · 3.4 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
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import sourceMaps from 'rollup-plugin-sourcemaps';
import bundleSize from 'rollup-plugin-bundle-size';
import ignore from 'rollup-plugin-ignore';
import json from 'rollup-plugin-json';
import pkg from './package.json';
const cjs = {
exports: 'named',
format: 'cjs',
sourcemap: true,
};
const esm = {
format: 'es',
sourcemap: true,
};
const getCJS = override => Object.assign({}, cjs, override);
const getESM = override => Object.assign({}, esm, override);
const babelConfig = ({ browser }) => ({
babelrc: false,
exclude: 'node_modules/**',
runtimeHelpers: true,
presets: [
[
'env',
Object.assign(
{},
{
loose: true,
modules: false,
},
browser ? {} : { targets: { node: '8.11.3' } },
),
],
'react',
],
plugins: [
'transform-runtime',
'external-helpers',
'transform-object-rest-spread',
['transform-class-properties', { loose: true }],
],
});
const commonPlugins = [json(), sourceMaps(), nodeResolve(), bundleSize()];
const configBase = {
globals: { react: 'React' },
external: [
'fbjs/lib/emptyObject',
'fbjs/lib/warning',
'@react-pdf/pdfkit',
'babel-runtime/core-js/promise',
'babel-runtime/helpers/objectWithoutProperties',
'babel-runtime/helpers/extends',
'babel-runtime/core-js/object/keys',
'babel-runtime/core-js/array/from',
'babel-runtime/core-js/json/stringify',
'babel-runtime/core-js/object/assign',
'babel-runtime/helpers/asyncToGenerator',
'babel-runtime/core-js/get-iterator',
'babel-runtime/helpers/inherits',
'babel-runtime/helpers/classCallCheck',
'babel-runtime/helpers/possibleConstructorReturn',
'babel-runtime/regenerator',
'babel-runtime/helpers/createClass',
'babel-runtime/helpers/typeof',
].concat(Object.keys(pkg.dependencies), Object.keys(pkg.peerDependencies)),
plugins: commonPlugins,
sourcemap: true,
};
const serverConfig = Object.assign({}, configBase, {
input: './src/node.js',
output: [
getESM({ file: 'dist/react-pdf.es.js' }),
getCJS({ file: 'dist/react-pdf.cjs.js' }),
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: false })),
replace({
BROWSER: JSON.stringify(false),
}),
),
external: configBase.external.concat(['fs', 'path']),
});
const serverProdConfig = Object.assign({}, serverConfig, {
output: [
getESM({ file: 'dist/react-pdf.es.min.js' }),
getCJS({ file: 'dist/react-pdf.cjs.min.js' }),
],
plugins: serverConfig.plugins.concat(uglify()),
});
const browserConfig = Object.assign({}, configBase, {
input: './src/dom.js',
output: [
getESM({ file: 'dist/react-pdf.browser.es.js' }),
getCJS({ file: 'dist/react-pdf.browser.cjs.js' }),
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: true })),
replace({
BROWSER: JSON.stringify(true),
}),
ignore(['fs', 'path']),
),
});
const browserProdConfig = Object.assign({}, browserConfig, {
output: [
getESM({ file: 'dist/react-pdf.browser.es.min.js' }),
getCJS({ file: 'dist/react-pdf.browser.cjs.min.js' }),
],
plugins: browserConfig.plugins.concat(uglify()),
});
export default [
serverConfig,
serverProdConfig,
browserConfig,
browserProdConfig,
];