-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
155 lines (145 loc) · 4.9 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const nodeResolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const json = require("@rollup/plugin-json");
const replace = require("@rollup/plugin-replace");
const { terser } = require("rollup-plugin-terser");
const pkg = require("./package.json");
const typescript = require("rollup-plugin-typescript2");
const { dts } = require("rollup-plugin-dts");
const nodePolyfills = require("rollup-plugin-polyfill-node");
const peerDependencies = [...Object.keys(pkg.peerDependencies || {})];
function makeCdnFilename(package) {
const major = pkg.version.split(".")[0];
let tag = "";
const preRelease = pkg.version.split("-")[1];
if (preRelease) {
tag = `-${preRelease.split(".")[0]}`;
}
let packagePart = "";
if (package) {
packagePart = `-${package}`;
}
return `v${major}${packagePart}${tag}.js`;
}
const replaceValues = {
preventAssignment: true,
values: {
__SDK_VERSION__: pkg.version,
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.NODE_DEBUG": JSON.stringify(process.env.NODE_DEBUG),
"process.env.AWF_BASE_URL": JSON.stringify(process.env.AWF_BASE_URL),
"process.env.AWF_API_BASE_URL": JSON.stringify(process.env.AWF_API_BASE_URL),
"process.env.AP_ROOM_BASE_URL": JSON.stringify(process.env.AP_ROOM_BASE_URL),
"process.env.RTCSTATS_URL": JSON.stringify(process.env.RTCSTATS_URL || "wss://rtcstats.srv.whereby.com"),
"process.env.REACT_APP_API_BASE_URL": JSON.stringify(
process.env.REACT_APP_API_BASE_URL || "https://api.whereby.dev"
),
"process.env.REACT_APP_SIGNAL_BASE_URL": JSON.stringify(
process.env.REACT_APP_SIGNAL_BASE_URL || "wss://signal.appearin.net"
),
"process.env.REACT_APP_IS_DEV": JSON.stringify(process.env.REACT_APP_IS_DEV),
},
};
const plugins = [
replace(replaceValues),
replace({
preventAssignment: true,
// jslib-media uses global.navigator for some gUM calls, replace these
delimiters: [" ", "."],
values: { "global.navigator.mediaDevices": " navigator.mediaDevices." },
}),
nodeResolve({
// only include @whereby/jslib-media and rtcstats in our bundle
preferBuiltins: true,
resolveOnly: [/@whereby\/jslib-media|rtcstats/],
}),
commonjs(),
typescript(),
];
module.exports = [
// Esm build of lib, to be used with bundlers
{
input: "src/lib/react/index.ts",
output: {
exports: "named",
file: "dist/react/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
{
input: "src/lib/embed/index.ts",
output: {
exports: "named",
file: "dist/embed/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
{
input: "src/lib/utils/index.ts",
output: {
exports: "named",
file: "dist/utils/index.esm.js",
format: "esm",
},
external: ["heresy", ...peerDependencies],
plugins,
},
// CDN builds
{
input: "src/lib/embed/index.ts",
output: {
file: `dist/cdn/${makeCdnFilename("embed")}`,
format: "iife",
name: "whereby",
},
plugins: [nodeResolve(), commonjs(), json(), terser(), replace(replaceValues), typescript()],
},
{
input: "src/lib/react/index.ts",
output: {
file: `dist/cdn/${makeCdnFilename("react")}`,
format: "iife",
name: "whereby.react",
globals: {
react: "React",
},
},
external: [...peerDependencies],
plugins: [
commonjs(), // Needs to come before `nodePolyfills`
nodePolyfills(),
nodeResolve({ browser: true, preferBuiltins: false }),
json(),
terser(),
replace({
preventAssignment: true,
// jslib-media uses global.navigator for some gUM calls, replace these
delimiters: [" ", "."],
values: { "global.navigator.mediaDevices": " navigator.mediaDevices." },
}),
replace(replaceValues),
typescript(),
],
},
// Type definitions
{
input: "src/lib/react/index.ts",
output: [{ file: "dist/react/index.d.ts", format: "es" }],
external: ["@whereby/jslib-media/src/webrtc/RtcManager"],
plugins: [dts()],
},
{
input: "src/lib/embed/index.ts",
output: [{ file: "dist/embed/index.d.ts", format: "es" }],
plugins: [dts()],
},
{
input: "src/lib/utils/index.ts",
output: [{ file: "dist/utils/index.d.ts", format: "es" }],
plugins: [dts()],
},
];