-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
104 lines (102 loc) · 2.05 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 fs from 'fs';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const { name, version, repository } = pkg;
const base = {
external: ['react'],
input: 'src/index.ts',
};
const bundles = {
esm: {
file: `dist/${name}.esm.js`,
minified: `dist/${name}.esm.min.js`,
tsconfig: './tsconfig.esm.json',
},
umd: {
file: `dist/${name}.umd.js`,
minified: `dist/${name}.umd.min.js`,
tsconfig: './tsconfig.umd.json',
umdGlobals: {
name,
exports: 'named',
globals: {
react: 'React',
},
},
},
};
const banner = `/*!
* ${name}
* ${repository?.url || ''}
*
* Version: ${version}
*
* Copyright KingSora | Rene Haas.
* https://github.com/KingSora
*
* Released under the MIT license.
* Date: ${new Date().toLocaleDateString('de-AT', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})}
*/`;
export default [
// output types:
{
...base,
output: [
{
file: `dist/${name}.js`,
sourcemap: false,
},
],
plugins: [
typescript({ tsconfig: './tsconfig.json' }),
{
name: 'deleteJsBundle',
writeBundle(options) {
fs.unlinkSync(options.file);
},
},
],
},
// output bundles:
...Object.keys(bundles).reduce((config, format) => {
const { file, minified, tsconfig, umdGlobals = {} } = bundles[format];
config.push({
...base,
output: {
file,
format,
banner,
sourcemap: true,
...umdGlobals,
},
plugins: [typescript({ tsconfig })],
});
if (minified) {
config.push({
...base,
input: file,
context: 'this',
output: [
{
format,
file: minified,
sourcemap: false,
plugins: [
terser({
output: {
comments: false,
},
}),
],
},
],
});
}
return config;
}, []),
];