-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
rollup.config.js
70 lines (62 loc) · 1.56 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
import path from 'path';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
const shouldMinify = process.env.NODE_ENV === 'production';
const shouldIncludeInBundle = ['tslib'];
const injectPackageVersion = () => {
const pkg = require('./package.json');
return `
if ( typeof window !== 'undefined' ) {
if ( !window['__REKA__'] ) {
window['__REKA__'] = {};
}
window['__REKA__']["${pkg.name}"] = "${pkg.version}";
}
`;
};
const createBundle = (config) => {
return {
input: config.input || './src/index.ts',
output: [
{
file: 'dist/index.mjs',
format: 'es',
intro: injectPackageVersion(),
...(config.output?.esm ?? {}),
},
{
file: 'dist/index.js',
format: 'cjs',
intro: injectPackageVersion(),
...(config.output?.cjs ?? {}),
},
],
external: (id) => {
if (config.external) {
return config.external(id);
}
return (
!id.startsWith('.') &&
!path.isAbsolute(id) &&
!shouldIncludeInBundle.includes(id)
);
},
plugins: Array.from(
new Set([
commonjs(),
nodeResolve(),
typescript({
declaration: false,
declarationDir: null,
}),
...(config.plugins || []),
shouldMinify && terser(),
])
),
};
};
export default function createRollupConfig(config) {
return [createBundle(config)];
}