From 4a02c59af85bddf4fc9f32105fc49dd4a64a93b2 Mon Sep 17 00:00:00 2001 From: arnold Date: Mon, 15 May 2023 18:45:07 -0400 Subject: [PATCH] Webpack build UMD. Also compile as ESM using tsc. Closes #1 --- .gitignore | 1 + package.json | 20 ++++++++++++++++---- src/listener.ts | 2 +- src/sender.ts | 2 +- tsconfig.esm.json | 14 ++++++++++++++ webpack.config.js | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 tsconfig.esm.json diff --git a/.gitignore b/.gitignore index ba6052e..19b728d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea package-lock.json +yarn.lock dist/ node_modules/ lib/ diff --git a/package.json b/package.json index 5b5124c..cee6114 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "clean": "rm -rf ./lib ./dist", "build": "webpack --mode production", - "compile": "tsc -p ./tsconfig.json", + "compile": "tsc && tsc -p ./tsconfig.esm.json", "test": "mocha --require ts-node/register 'test/**/*.spec.ts'", "lint": "eslint src --ext .ts,.tsx", "lint-fix": "eslint src --ext .ts,.tsx --fix" @@ -14,9 +14,21 @@ "license": "MIT", "main": "./lib/index.js", "exports": { - ".": "./lib/index.js", - "./sender": "./lib/sender.js", - "./listener": "./lib/listener.js" + ".": { + "types": "./lib/index.d.ts", + "import": "./lib/esm/index.js", + "default": "./lib/index.js" + }, + "./sender": { + "types": "./lib/sender.d.ts", + "import": "./lib/esm/sender.js", + "default": "./lib/sender.js" + }, + "./listener": { + "types": "./lib/listener.d.ts", + "import": "./lib/esm/listener.js", + "default": "./lib/listener.js" + } }, "files": [ "lib", diff --git a/src/listener.ts b/src/listener.ts index b5b404c..a8fa569 100644 --- a/src/listener.ts +++ b/src/listener.ts @@ -2,7 +2,7 @@ import {CALL_TYPE, RESPONSE_TYPE} from "./constants"; import {MessageTarget, RPCRequest, WindowLike} from "./types"; export default class Listener { - public fallbackSource: MessageTarget; // Only for testing + public fallbackSource?: MessageTarget; // Only for testing constructor(private readonly methods: {[fn: string]: (...args: any[]) => any}) {} diff --git a/src/sender.ts b/src/sender.ts index 39a4b2b..ee384f5 100644 --- a/src/sender.ts +++ b/src/sender.ts @@ -63,7 +63,7 @@ export function connect Promise