This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
85 lines (80 loc) · 2.04 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
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import replace from 'rollup-plugin-replace';
import { uglify } from 'rollup-plugin-uglify';
import pkg from './package.json';
const deps = Object.keys(pkg.dependencies || {});
const peers = Object.keys(pkg.peerDependencies || {});
const allExternal = [...deps, ...peers];
const makeExternalPredicate = externalsArr => {
if (externalsArr.length === 0) {
return () => false;
}
const externalPattern = new RegExp(`^(${externalsArr.join('|')})($|/)`);
return id => externalPattern.test(id);
};
const makeBabelConfig = ({ useCoreJS = false, useESModules = true }) => ({
babelrc: false,
configFile: false,
exclude: /node_modules\/(?!callbag-)/,
extensions: ['.js', '.ts'],
plugins: [['@babel/plugin-transform-runtime', { useESModules }]],
runtimeHelpers: true,
presets: [
[
'@babel/env',
{
loose: true,
modules: false,
...(useCoreJS ? { useBuiltIns: 'usage', corejs: 3 } : {})
}
]
]
});
const createConfig = ({ output, min = false, external = 'all', env }) => ({
input: './src/index.ts',
output,
external: makeExternalPredicate(external === 'all' ? allExternal : peers),
plugins: [
resolve(),
commonjs({ include: 'node_modules/**' }),
typescript({ useTsconfigDeclarationDir: true }),
babel(
makeBabelConfig({
useCoreJS: output.format === 'umd',
useESModules: output.format !== 'cjs'
})
),
env &&
replace({
'process.env.NODE_ENV': JSON.stringify(env)
}),
min && uglify()
]
});
export default [
createConfig({
output: {
format: 'es',
file: pkg.module
}
}),
createConfig({
output: {
format: 'cjs',
file: pkg.main
}
}),
createConfig({
output: {
format: 'umd',
file: pkg.unpkg,
name: 'LiveChat'
},
external: 'peers',
env: 'production',
min: true
})
];