Skip to content

Commit

Permalink
Webpack build UMD.
Browse files Browse the repository at this point in the history
Also compile as ESM using tsc.
Closes #1
  • Loading branch information
jasny committed May 15, 2023
1 parent 944539d commit 4a02c59
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
package-lock.json
yarn.lock
dist/
node_modules/
lib/
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {}

Expand Down
2 changes: 1 addition & 1 deletion src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function connect<T extends {[name: string]: (...args: any) => Promise<any
const {id, error, result} = event.data;
if (!promises.has(id)) throw new Error(`No promise waiting for call id ${id} on channel ${channel}`);

const {resolve, reject, timeoutId} = promises.get(id);
const {resolve, reject, timeoutId} = promises.get(id)!;
promises.delete(id);

if (timeoutId) parent.clearTimeout(timeoutId);
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "",
"target": "es2020",
"module": "es6",
"moduleResolution": "node16",
"noUnusedLocals": true,
"sourceMap": true,
"rootDir": "src",
"outDir": "lib/esm"
},
"include": ["src"],
}
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require("path");

module.exports = {
experiments: {
outputModule: true,
outputModule: false,
},
entry: {
sender: "./src/sender.ts",
Expand All @@ -15,7 +15,7 @@ module.exports = {
asyncChunks: false,
library: {
name: "simpleIframeRpc",
type: "amd"
type: "umd"
}
},
module: {
Expand Down

0 comments on commit 4a02c59

Please sign in to comment.