update bundle config

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent adffe1e9ad
commit c97590edc7
3 changed files with 109 additions and 19 deletions

View File

@@ -1,42 +1,126 @@
import typescript from 'rollup-plugin-typescript';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
function toRecordPath(path) {
return path
.replace(/^([\w]+)\//, '$1/record/')
.replace('rrweb', 'rrweb-record');
}
function toMinPath(path) {
return path.replace(/\.js$/, '.min.js');
}
export default [
// browser(record only)
{
input: './src/record/index.ts',
plugins: [typescript(), resolve()],
output: [
{
name: 'record',
format: 'umd',
file: toRecordPath(pkg.unpkg),
},
],
},
{
input: './src/record/index.ts',
plugins: [typescript(), resolve(), terser()],
output: [
{
name: 'record',
format: 'umd',
file: toMinPath(toRecordPath(pkg.unpkg)),
},
],
},
// CommonJS(record only)
{
input: './src/record/index.ts',
plugins: [typescript(), resolve()],
output: [
{
format: 'cjs',
file: './dist/record/index.js',
},
{
format: 'esm',
file: './dist/record/module.js',
},
{
name: 'record',
format: 'iife',
file: './dist/record/browser.js',
file: toRecordPath(pkg.main),
},
],
},
// ES module(record only)
{
input: './src/record/index.ts',
plugins: [typescript(), resolve()],
output: [
{
format: 'esm',
file: toRecordPath(pkg.module),
},
],
},
{
input: './src/record/index.ts',
plugins: [typescript(), resolve(), terser()],
output: [
{
format: 'esm',
file: toMinPath(toRecordPath(pkg.module)),
},
],
},
// browser
{
input: './src/index.ts',
plugins: [typescript(), resolve()],
output: [
{
name: 'rrweb',
format: 'umd',
file: pkg.unpkg,
},
],
},
{
input: './src/index.ts',
plugins: [typescript(), resolve(), terser()],
output: [
{
name: 'rrweb',
format: 'umd',
file: toMinPath(pkg.unpkg),
},
],
},
// CommonJS
{
input: './src/index.ts',
plugins: [typescript(), resolve()],
output: [
{
format: 'cjs',
file: './dist/index.js',
file: pkg.main,
},
],
},
// ES module
{
input: './src/index.ts',
plugins: [typescript(), resolve()],
output: [
{
format: 'esm',
file: './dist/module.js',
file: pkg.module,
},
],
},
{
input: './src/index.ts',
plugins: [typescript(), resolve(), terser()],
output: [
{
name: 'rrweb',
format: 'iife',
file: './dist/browser.js',
format: 'esm',
file: toMinPath(pkg.module),
},
],
},