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
180 lines
3.4 KiB
JavaScript
180 lines
3.4 KiB
JavaScript
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;
|