continue #199: redesign the bundled file structure

According to @eoghanmurray's suggestion, we can support three
main scenarios:
1. record only
2. replay only
3. all in one

Since we have implemented the packer feature, which has a big
influence in bundle size, we provide another three bundles:
1. record and pack
2. replay and unpack
3. all in one with pack and unpack
This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 81b3407dd7
commit 191908aa1d
6 changed files with 40 additions and 24 deletions

View File

@@ -17,8 +17,8 @@
"keywords": [
"rrweb"
],
"main": "lib/rrweb-boost.js",
"module": "es/rrweb/src/boost.js",
"main": "lib/rrweb-all.js",
"module": "es/rrweb/entries/all.js",
"unpkg": "dist/rrweb.js",
"sideEffects": false,
"typings": "typings/index.d.ts",

View File

@@ -11,20 +11,26 @@ function toRecordPath(path) {
.replace('rrweb', 'rrweb-record');
}
function toPackPath(path) {
function toRecordPackPath(path) {
return path
.replace(/^([\w]+)\//, '$1/packer/')
.replace('rrweb', 'rrweb-pack');
.replace(/^([\w]+)\//, '$1/record/')
.replace('rrweb', 'rrweb-record-pack');
}
function toPackerPath(path) {
function toReplayPath(path) {
return path
.replace(/^([\w]+)\//, '$1/packer/')
.replace('rrweb', 'rrweb-packer');
.replace(/^([\w]+)\//, '$1/replay/')
.replace('rrweb', 'rrweb-replay');
}
function toBoostPath(path) {
return path.replace('rrweb', 'rrweb-boost');
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) {
@@ -44,17 +50,23 @@ const baseConfigs = [
name: 'rrwebRecord',
pathFn: toRecordPath,
},
// pack only
// record and pack
{
input: './src/packer/pack.ts',
name: 'rrwebPack',
pathFn: toPackPath,
input: './src/entries/record-pack.ts',
name: 'rrwebRecord',
pathFn: toRecordPackPath,
},
// packer only
// replay only
{
input: './src/packer/index.ts',
name: 'rrwebPacker',
pathFn: toPackerPath,
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
{
@@ -64,9 +76,9 @@ const baseConfigs = [
},
// all in one
{
input: './src/boost.ts',
name: 'rrwebBoost',
pathFn: toBoostPath,
input: './src/entries/all.ts',
name: 'rrweb',
pathFn: toAllPath,
},
];
@@ -119,7 +131,7 @@ for (const c of baseConfigs) {
output: [
{
format: 'cjs',
file: c.pathFn(pkg.main),
file: c.pathFn('lib/rrweb.js'),
},
],
});

View File

@@ -1,2 +0,0 @@
export * from './index';
export * from './packer';

2
src/entries/all.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from '../index';
export * from '../packer';

View File

@@ -0,0 +1,2 @@
export * from '../record/index';
export * from '../packer/pack';

View File

@@ -0,0 +1,2 @@
export * from '../replay';
export * from '../packer/unpack';