Skip to content

Commit

Permalink
continue #199: redesign the bundled file structure
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Yuyz0112 committed Jun 15, 2020
1 parent 4cf1967 commit a3b1ab6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 32 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 toReplayPath(path) {
return path
.replace(/^([\w]+)\//, '$1/replay/')
.replace('rrweb', 'rrweb-replay');
}

function toPackerPath(path) {
function toReplayUnpackPath(path) {
return path
.replace(/^([\w]+)\//, '$1/packer/')
.replace('rrweb', 'rrweb-packer');
.replace(/^([\w]+)\//, '$1/replay/')
.replace('rrweb', 'rrweb-replay-unpack');
}

function toBoostPath(path) {
return path.replace('rrweb', 'rrweb-boost');
function toAllPath(path) {
return path.replace('rrweb', 'rrweb-all');
}

function toMinPath(path) {
Expand All @@ -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,
},
// replay only
{
input: './src/replay/index.ts',
name: 'rrwebReplay',
pathFn: toReplayPath,
},
// packer only
// replay and unpack
{
input: './src/packer/index.ts',
name: 'rrwebPacker',
pathFn: toPackerPath,
input: './src/entries/replay-unpack.ts',
name: 'rrwebReplay',
pathFn: toReplayUnpackPath,
},
// record and replay
{
Expand All @@ -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,
},
];

Expand Down Expand Up @@ -119,7 +131,7 @@ for (const c of baseConfigs) {
output: [
{
format: 'cjs',
file: c.pathFn(pkg.main),
file: c.pathFn('lib/rrweb.js'),
},
],
});
Expand Down
2 changes: 0 additions & 2 deletions src/boost.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/entries/all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../index';
export * from '../packer';
2 changes: 2 additions & 0 deletions src/entries/record-pack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../record/index';
export * from '../packer/pack';
2 changes: 2 additions & 0 deletions src/entries/replay-unpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '../replay';
export * from '../packer/unpack';

0 comments on commit a3b1ab6

Please sign in to comment.