diff --git a/package.json b/package.json index b4a115f5..6ec9df87 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,9 @@ "rrweb" ], "main": "lib/rrweb.js", - "module": "es/rrweb.js", + "module": "es/rrweb/src/index.js", "unpkg": "dist/rrweb.js", + "sideEffects": false, "typings": "typings/index.d.ts", "files": [ "dist", @@ -45,7 +46,7 @@ "jest-snapshot": "^23.6.0", "mocha": "^5.2.0", "puppeteer": "^1.11.0", - "rollup": "^0.66.6", + "rollup": "^2.3.3", "rollup-plugin-commonjs": "^9.2.0", "rollup-plugin-node-resolve": "^3.4.0", "rollup-plugin-postcss": "^1.6.2", diff --git a/rollup.config.js b/rollup.config.js index dcffe98a..ece5193a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -98,22 +98,11 @@ for (const c of baseConfigs) { configs.push({ input: c.input, plugins, + preserveModules: true, 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, + dir: 'es/rrweb', }, ], }); diff --git a/test/integration.test.ts b/test/integration.test.ts index 71e4846f..8f72f7ed 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -3,17 +3,20 @@ import * as path from 'path'; import * as puppeteer from 'puppeteer'; import { assertSnapshot, launchPuppeteer } from './utils'; import { Suite } from 'mocha'; -import { recordOptions } from '../src/types'; +import { recordOptions, eventWithTime } from '../src/types'; interface ISuite extends Suite { code: string; browser: puppeteer.Browser; } -describe('record integration tests', function(this: ISuite) { +describe('record integration tests', function (this: ISuite) { this.timeout(10_000); - const getHtml = (fileName: string, options: recordOptions = {}): string => { + const getHtml = ( + fileName: string, + options: recordOptions = {}, + ): string => { const filePath = path.resolve(__dirname, `./html/${fileName}`); const html = fs.readFileSync(filePath, 'utf8'); return html.replace( diff --git a/test/record.test.ts b/test/record.test.ts index e706ad6d..417c3a27 100644 --- a/test/record.test.ts +++ b/test/record.test.ts @@ -24,13 +24,15 @@ interface ISuite extends Suite { interface IWindow extends Window { rrweb: { - record: (options: recordOptions) => listenerHandler | undefined; + record: ( + options: recordOptions, + ) => listenerHandler | undefined; addCustomEvent(tag: string, payload: T): void; }; emit: (e: eventWithTime) => undefined; } -describe('record', function(this: ISuite) { +describe('record', function (this: ISuite) { before(async () => { this.browser = await launchPuppeteer(); @@ -58,7 +60,7 @@ describe('record', function(this: ISuite) { this.events.push(e); }); - page.on('console', msg => console.log('PAGE LOG:', msg.text())); + page.on('console', (msg) => console.log('PAGE LOG:', msg.text())); }); afterEach(async () => { @@ -223,14 +225,14 @@ describe('record', function(this: ISuite) { }); await this.page.waitFor(10); const styleSheetRuleEvents = this.events.filter( - e => + (e) => e.type === EventType.IncrementalSnapshot && e.data.source === IncrementalSource.StyleSheetRule, ); - const addRuleCount = styleSheetRuleEvents.filter(e => + const addRuleCount = styleSheetRuleEvents.filter((e) => Boolean((e.data as styleSheetRuleData).adds), ).length; - const removeRuleCount = styleSheetRuleEvents.filter(e => + const removeRuleCount = styleSheetRuleEvents.filter((e) => Boolean((e.data as styleSheetRuleData).removes), ).length; // sync insert/delete should be ignored