-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.js
104 lines (97 loc) · 2.67 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
import * as fs from 'fs';
import * as path from 'path';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import sizes from 'rollup-plugin-sizes';
import visualizer from 'rollup-plugin-visualizer';
// eslint-disable-next-line @typescript-eslint/no-var-requires,no-undef
const packageJson = require('./package.json');
const license = fs.readFileSync(path.resolve(__dirname, './LICENSE'), 'utf-8');
const external = ['react', 'react-dom', 'react-query', 'rxjs'];
const globals = {
react: 'React',
'react-dom': 'ReactDOM',
'react-query': 'ReactQuery',
rxjs: 'rxjs',
'rxjs/operators': 'rxjs.operators',
};
const inputSources = [
['src/index.ts', 'ReactQuerySubscription', 'react-query-subscription'],
];
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx'];
const babelConfig = {
extensions,
babelHelpers: 'runtime',
babelrc: true,
exclude: '**/node_modules/**',
};
const resolveConfig = { browser: true, extensions };
// Throw on warning
function onwarn(warning) {
throw Error(warning.message);
}
const createBanner = (name, file) => `/**
* @license ${name} v${packageJson.version}
* ${file}
*
* ${license.replace(/\n$/, '').replace(/\n/g, '\n * ')}
*/
`;
export default inputSources
.map(([input, name, file]) => {
return [
{
input,
onwarn,
output: {
file: `dist/${file}.development.js`,
format: 'umd',
name,
sourcemap: true,
banner: createBanner(name, `${file}.development.js`),
globals,
},
external,
plugins: [
resolve(resolveConfig),
babel(babelConfig),
commonjs(),
peerDepsExternal(),
],
},
{
input: input,
output: {
file: `dist/${file}.production.min.js`,
format: 'umd',
name,
sourcemap: true,
banner: createBanner(name, `${file}.production.min.js`),
globals,
},
external,
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
delimiters: ['', ''],
preventAssignment: true,
}),
resolve(resolveConfig),
babel(babelConfig),
commonjs(),
peerDepsExternal(),
terser(),
sizes(),
visualizer({
filename: 'stats.json',
json: true,
}),
],
},
];
})
.flat();