From c97590edc7a79d41d248fa3db070aee23baf5a46 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] update bundle config --- .gitignore | 2 + package.json | 12 +++-- rollup.config.js | 114 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 109 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 96ba215c..9724a7cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ node_modules package-lock.json build dist +es +lib temp diff --git a/package.json b/package.json index 5712d83c..8c38c983 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,6 @@ "name": "rrweb", "version": "0.6.0", "description": "record and replay the web", - "main": "dist/index.js", - "module": "dist/module.js", "scripts": { "test": "TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts", "repl": "TS_NODE_CACHE=false TS_NODE_FILES=true ts-node test/repl.ts", @@ -16,8 +14,14 @@ "keywords": [ "rrweb" ], + "main": "lib/rrweb.js", + "module": "es/rrweb.js", + "unpkg": "dist/rrweb.js", + "typings": "./index.d.ts", "files": [ "dist", + "lib", + "es", "index.d.ts", "src/types.ts" ], @@ -37,9 +41,9 @@ "jest-snapshot": "^23.6.0", "mocha": "^5.2.0", "puppeteer": "^1.9.0", - "rewire": "^4.0.1", "rollup": "^0.66.6", "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-terser": "^3.0.0", "rollup-plugin-typescript": "^1.0.0", "ts-node": "^7.0.1", "tslib": "^1.9.3", @@ -48,6 +52,6 @@ }, "dependencies": { "mitt": "^1.1.3", - "rrweb-snapshot": "^0.6.0" + "rrweb-snapshot": "^0.6.1" } } diff --git a/rollup.config.js b/rollup.config.js index a06d92f9..5bad8d4b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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), }, ], },