Packer (#172)
* introduce pako and add general packer interface * add tests for packer * use function API instead of class API for better tree shaking support * refcatoring the rollup bundle config
This commit is contained in:
248
rollup.config.js
248
rollup.config.js
@@ -11,176 +11,122 @@ function toRecordPath(path) {
|
||||
.replace('rrweb', 'rrweb-record');
|
||||
}
|
||||
|
||||
function toPackPath(path) {
|
||||
return path
|
||||
.replace(/^([\w]+)\//, '$1/packer/')
|
||||
.replace('rrweb', 'rrweb-pack');
|
||||
}
|
||||
|
||||
function toMinPath(path) {
|
||||
return path.replace(/\.js$/, '.min.js');
|
||||
}
|
||||
|
||||
let configs = [
|
||||
// browser(record only)
|
||||
const namedExports = {
|
||||
'pako/dist/pako_deflate': ['deflate'],
|
||||
'pako/dist/pako_inflate': ['inflate'],
|
||||
pako: ['deflate'],
|
||||
};
|
||||
|
||||
const baseConfigs = [
|
||||
{
|
||||
input: './src/record/index.ts',
|
||||
plugins: [resolve(), commonjs(), typescript()],
|
||||
output: [
|
||||
{
|
||||
name: 'rrwebRecord',
|
||||
format: 'iife',
|
||||
file: toRecordPath(pkg.unpkg),
|
||||
},
|
||||
],
|
||||
name: 'rrwebRecord',
|
||||
pathFn: toRecordPath,
|
||||
},
|
||||
{
|
||||
input: './src/record/index.ts',
|
||||
plugins: [resolve(), commonjs(), typescript(), terser()],
|
||||
output: [
|
||||
{
|
||||
name: 'rrwebRecord',
|
||||
format: 'iife',
|
||||
file: toMinPath(toRecordPath(pkg.unpkg)),
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
// CommonJS(record only)
|
||||
{
|
||||
input: './src/record/index.ts',
|
||||
plugins: [resolve(), commonjs(), typescript()],
|
||||
output: [
|
||||
{
|
||||
format: 'cjs',
|
||||
file: toRecordPath(pkg.main),
|
||||
},
|
||||
],
|
||||
},
|
||||
// ES module(record only)
|
||||
{
|
||||
input: './src/record/index.ts',
|
||||
plugins: [resolve(), commonjs(), typescript()],
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: toRecordPath(pkg.module),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: './src/record/index.ts',
|
||||
plugins: [resolve(), commonjs(), typescript(), terser()],
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: toMinPath(toRecordPath(pkg.module)),
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
// browser
|
||||
{
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: false,
|
||||
inject: false,
|
||||
}),
|
||||
],
|
||||
output: [
|
||||
{
|
||||
name: 'rrweb',
|
||||
format: 'iife',
|
||||
file: pkg.unpkg,
|
||||
},
|
||||
],
|
||||
input: './src/packer/pack.ts',
|
||||
name: 'rrwebPack',
|
||||
pathFn: toPackPath,
|
||||
},
|
||||
{
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: true,
|
||||
minimize: true,
|
||||
sourceMap: true,
|
||||
}),
|
||||
terser(),
|
||||
],
|
||||
output: [
|
||||
{
|
||||
name: 'rrweb',
|
||||
format: 'iife',
|
||||
file: toMinPath(pkg.unpkg),
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
// CommonJS
|
||||
{
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: false,
|
||||
inject: false,
|
||||
}),
|
||||
],
|
||||
output: [
|
||||
{
|
||||
format: 'cjs',
|
||||
file: pkg.main,
|
||||
},
|
||||
],
|
||||
},
|
||||
// ES module
|
||||
{
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: false,
|
||||
inject: false,
|
||||
}),
|
||||
],
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: pkg.module,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: false,
|
||||
inject: false,
|
||||
}),
|
||||
terser(),
|
||||
],
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: toMinPath(pkg.module),
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
name: 'rrweb',
|
||||
pathFn: (p) => p,
|
||||
},
|
||||
];
|
||||
|
||||
let configs = [];
|
||||
|
||||
for (const c of baseConfigs) {
|
||||
const plugins = [
|
||||
resolve(),
|
||||
commonjs({ namedExports }),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: false,
|
||||
inject: false,
|
||||
}),
|
||||
];
|
||||
const minifyPlugins = plugins.concat(terser());
|
||||
// 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: minifyPlugins,
|
||||
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(pkg.main),
|
||||
},
|
||||
],
|
||||
});
|
||||
// ES module
|
||||
configs.push({
|
||||
input: c.input,
|
||||
plugins,
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: c.pathFn(pkg.module),
|
||||
},
|
||||
],
|
||||
});
|
||||
// ES module + minify
|
||||
configs.push({
|
||||
input: c.input,
|
||||
plugins: minifyPlugins,
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
file: toMinPath(c.pathFn(pkg.module)),
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.BROWSER_ONLY) {
|
||||
configs = {
|
||||
input: './src/index.ts',
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
commonjs({
|
||||
namedExports,
|
||||
}),
|
||||
typescript(),
|
||||
postcss({
|
||||
extract: true,
|
||||
|
||||
Reference in New Issue
Block a user