-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.ts
108 lines (95 loc) · 2.38 KB
/
rollup.config.ts
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
/* -------------------------------------------------------------------------- */
/* External Dependencies */
/* -------------------------------------------------------------------------- */
import pluginTypescript from '@rollup/plugin-typescript';
import pluginCommonjs from '@rollup/plugin-commonjs';
import pluginNodeResolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import multiInput from 'rollup-plugin-multi-input';
/* -------------------------- Internal Dependencies ------------------------- */
import pkg from './package.json';
import defaultTsConfig from './tsconfig.json';
const moduleName = pkg.name.replace(/^@.*\//, '');
const inputFileName = ['src/**/*.ts'];
const author = pkg.author;
const bundles = {
es: 'dist/bundle-es',
cjs: 'dist/bundle-cjs',
browser: 'dist/bundle-browser',
};
const banner = `
/**
* ${moduleName}.js
* @summary ${pkg.description}
* @version v${pkg.version}
* @author ${author}
* @license Released under the ${pkg.license} license.
* @copyright Adenekan Wonderful 2021
*/
`;
const pluginsSetups = bundle => ({
external: ['react', 'react-dom'],
plugins: [
multiInput(),
pluginTypescript({
...defaultTsConfig.compilerOptions,
...{
declaration: true,
emitDeclarationOnly: true,
outDir: `${bundle}`,
declarationDir: `${bundle}`,
exclude: ['node_modules', 'dist'],
},
}),
pluginCommonjs({
extensions: ['.ts', '.tsx'],
}),
pluginNodeResolve({
browser: bundle === bundles.browser ? true : false,
}),
],
});
export default [
{
input: inputFileName,
output: [
{
name: moduleName,
dir: bundles.browser,
format: 'esm',
sourcemap: 'inline',
banner,
plugins: [terser()],
},
],
...pluginsSetups(bundles.browser),
},
// ES
{
input: inputFileName,
output: [
{
dir: bundles.es,
format: 'es',
sourcemap: 'inline',
banner,
exports: 'named',
},
],
...pluginsSetups(bundles.es),
},
// CommonJS
{
input: inputFileName,
output: [
{
dir: bundles.cjs,
format: 'cjs',
sourcemap: 'inline',
banner,
exports: 'named',
},
],
...pluginsSetups(bundles.cjs),
},
];