From 215b2b319bc01af1a1eebea310851e95162148a5 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Thu, 11 Oct 2018 16:46:34 +0800 Subject: [PATCH] update bundle configs --- .gitignore | 1 + package.json | 7 ++++++- rollup.config.js | 22 ++++++++++++++++++++++ src/utils.ts | 4 ++-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index 6ccc9d84..f35f48b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules package-lock.json build +dist diff --git a/package.json b/package.json index 9b2f5981..76904893 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "record and replay the web", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "bundle": "rollup --config" }, "repository": { "type": "git", @@ -20,6 +21,10 @@ }, "homepage": "https://github.com/rrweb-io/rrweb#readme", "devDependencies": { + "rollup": "^0.66.6", + "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-typescript": "^1.0.0", + "tslib": "^1.9.3", "tslint": "^4.5.1", "typescript": "^3.1.1" }, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..ce25d583 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,22 @@ +import typescript from 'rollup-plugin-typescript'; +import resolve from 'rollup-plugin-node-resolve'; + +export default { + input: './src/index.ts', + plugins: [typescript(), resolve()], + output: [ + { + format: 'cjs', + file: './dist/index.js', + }, + { + format: 'esm', + file: './dist/module.js', + }, + { + name: 'rrweb', + format: 'iife', + file: './dist/browser.js', + }, + ], +}; diff --git a/src/utils.ts b/src/utils.ts index b33da50a..9539319a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -48,13 +48,13 @@ export function throttle( let args = arguments; if (remaining <= 0 || remaining > wait) { if (timeout) { - clearTimeout(timeout); + window.clearTimeout(timeout); timeout = null; } previous = now; func.apply(context, args); } else if (!timeout && options.trailing !== false) { - timeout = setTimeout(() => { + timeout = window.setTimeout(() => { previous = options.leading === false ? 0 : Date.now(); timeout = null; func.apply(context, args);