forked from rrweb-io/rrweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
179 lines (167 loc) · 3.35 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import pkg from './package.json';
function toRecordPath(path) {
return path
.replace(/^([\w]+)\//, '$1/record/')
.replace('rrweb', 'rrweb-record');
}
function toRecordPackPath(path) {
return path
.replace(/^([\w]+)\//, '$1/record/')
.replace('rrweb', 'rrweb-record-pack');
}
function toReplayPath(path) {
return path
.replace(/^([\w]+)\//, '$1/replay/')
.replace('rrweb', 'rrweb-replay');
}
function toReplayUnpackPath(path) {
return path
.replace(/^([\w]+)\//, '$1/replay/')
.replace('rrweb', 'rrweb-replay-unpack');
}
function toAllPath(path) {
return path.replace('rrweb', 'rrweb-all');
}
function toMinPath(path) {
return path.replace(/\.js$/, '.min.js');
}
const namedExports = {
'pako/dist/pako_deflate': ['deflate'],
'pako/dist/pako_inflate': ['inflate'],
pako: ['deflate'],
};
const baseConfigs = [
// record only
{
input: './src/record/index.ts',
name: 'rrwebRecord',
pathFn: toRecordPath,
},
// record and pack
{
input: './src/entries/record-pack.ts',
name: 'rrwebRecord',
pathFn: toRecordPackPath,
},
// replay only
{
input: './src/replay/index.ts',
name: 'rrwebReplay',
pathFn: toReplayPath,
},
// replay and unpack
{
input: './src/entries/replay-unpack.ts',
name: 'rrwebReplay',
pathFn: toReplayUnpackPath,
},
// record and replay
{
input: './src/index.ts',
name: 'rrweb',
pathFn: (p) => p,
},
// all in one
{
input: './src/entries/all.ts',
name: 'rrweb',
pathFn: toAllPath,
},
];
let configs = [];
for (const c of baseConfigs) {
const basePlugins = [resolve(), commonjs({ namedExports }), typescript()];
const plugins = basePlugins.concat(
postcss({
extract: false,
inject: false,
}),
);
// browser
configs.push({
input: c.input,
plugins,
output: [
{
name: c.name,
format: 'iife',
file: c.pathFn(pkg.unpkg),
},
],
});
// browser + minify
configs.push({
input: c.input,
plugins: basePlugins.concat(
postcss({
extract: true,
minimize: true,
sourceMap: true,
}),
terser(),
),
output: [
{
name: c.name,
format: 'iife',
file: toMinPath(c.pathFn(pkg.unpkg)),
sourcemap: true,
},
],
});
// CommonJS
configs.push({
input: c.input,
plugins,
output: [
{
format: 'cjs',
file: c.pathFn('lib/rrweb.js'),
},
],
});
// ES module
configs.push({
input: c.input,
plugins,
preserveModules: true,
output: [
{
format: 'esm',
dir: 'es/rrweb',
},
],
});
}
if (process.env.BROWSER_ONLY) {
configs = {
input: './src/index.ts',
plugins: [
resolve(),
commonjs({
namedExports,
}),
typescript(),
postcss({
extract: true,
minimize: true,
sourceMap: true,
}),
terser(),
],
output: [
{
name: 'rrweb',
format: 'iife',
file: toMinPath(pkg.unpkg),
sourcemap: true,
},
],
};
}
export default configs;