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
2020-06-15 18:10:39 +08:00
parent 4cf196718c
commit a3b1ab6d9e
6 changed files with 40 additions and 24 deletions

View File

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

View File

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