From 4287fb4810e4c7710fafc8055cd9df0f3ef21bb7 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Tue, 13 Nov 2018 19:10:34 +0800 Subject: [PATCH] update bundle config --- .gitignore | 2 ++ package.json | 9 ++++-- rollup.config.js | 82 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index f35f48b8..2c597d03 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ node_modules package-lock.json build dist +es +lib diff --git a/package.json b/package.json index 0004aa67..cb7d0b8c 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,6 @@ "name": "rrweb-snapshot", "version": "0.6.0", "description": "rrweb's component to take a snapshot of DOM, aka DOM serializer", - "main": "dist/index.js", - "module": "dist/module.js", "scripts": { "test": "TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.ts", "bundle": "rollup --config" @@ -17,8 +15,14 @@ "snapshot", "DOM" ], + "main": "lib/rrweb-snapshot.js", + "module": "es/rrweb-snapshot.js", + "unpkg": "dist/rrweb-snapshot.js", + "typings": "./index.d.ts", "files": [ "dist", + "lib", + "es", "index.d.ts", "src/types.ts" ], @@ -38,6 +42,7 @@ "mocha": "^5.2.0", "puppeteer": "^1.9.0", "rollup": "^0.66.4", + "rollup-plugin-terser": "^3.0.0", "rollup-plugin-typescript": "^1.0.0", "ts-node": "^7.0.1", "tslib": "^1.9.3", diff --git a/rollup.config.js b/rollup.config.js index dc2cd261..e40d7537 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,21 +1,65 @@ import typescript from 'rollup-plugin-typescript'; +import { terser } from 'rollup-plugin-terser'; +import pkg from './package.json'; -export default { - input: './src/index.ts', - plugins: [typescript()], - output: [ - { - format: 'cjs', - file: './dist/index.js', - }, - { - format: 'esm', - file: './dist/module.js', - }, - { - name: 'rrwebSnapshot', - format: 'iife', - file: './dist/browser.js', - }, - ], -}; +function toMinPath(path) { + return path.replace(/\.js$/, '.min.js'); +} + +export default [ + // browser + { + input: './src/index.ts', + plugins: [typescript()], + output: [ + { + name: 'rrwebSnapshot', + format: 'umd', + file: pkg.unpkg, + }, + ], + }, + { + input: './src/index.ts', + plugins: [typescript(), terser()], + output: [ + { + name: 'rrwebSnapshot', + format: 'umd', + file: toMinPath(pkg.unpkg), + }, + ], + }, + // CommonJS + { + input: './src/index.ts', + plugins: [typescript()], + output: [ + { + format: 'cjs', + file: pkg.main, + }, + ], + }, + // ES module + { + input: './src/index.ts', + plugins: [typescript()], + output: [ + { + format: 'esm', + file: pkg.module, + }, + ], + }, + { + input: './src/index.ts', + plugins: [typescript(), terser()], + output: [ + { + format: 'esm', + file: toMinPath(pkg.module), + }, + ], + }, +];