Implementation of lightweight message passing logic for TypeScript.
npm install @uupaa/messagepassing``sh`
$ npm i -S @uupaa/messagepassing
`ts--moduleResolution
// Pattern 1 (recommended): import complete relative path without and --baseUrl compiler options.
// For import url, specify the complete relative path.
// This works with node.js and browser. Please consider bundled into one file.
import { MessagePassing, MessageSubscriber, MessageOptions, MessageResult } from "../node_modules/@uupaa/messagepassing/lib/MessagePassing.esm.js";
/*
{
"compilerOptions": {
"module": "ESNext",
//"moduleResolution": "node",
//"baseUrl": "./",
}
}
*/
`
`ts--moduleResolution
// Pattern 2: import package name with and --baseUrl compiler options.
// For import url, specify the short package name.
// This works in node.js, but does not work if you import directly from the browser.
import { MessagePassing, MessageSubscriber, MessageOptions, MessageResult } from "@uupaa/messagepassing";
/*
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"baseUrl": "./",
}
}
*/
`
The npm run build command, build to lib/MessagePassing.js file.
The npm run bundle:all command, bundle to lib/MessagePassing.esm.js and lib/MessagePassing.cjs.js files.
Other commands.
| command | input | output |
|----------------------|---------------|-------------|
| npm run build | ts/ | lib/MessagePassing.js lib/MessagePassing.d.ts
|npm run bundle
| | lib/MessagePassing.js | lib/MessagePassing.esm.js |npm run bundle:esm
| | lib/MessagePassing.js | lib/MessagePassing.esm.js |npm run bundle:cjs
| | lib/MessagePassing.js | lib/MessagePassing.cjs.js |npm run bundle:all
| | lib/MessagePassing.js | lib/MessagePassing.esm.js lib/MessagePassing.cjs.js |npm run watch
| | | |
| Browser |