js-message works with bundlers and without a bundler.
Bundlers resolve the bare js-message import normally. Native browser ESM resolves it through a standard import map, with no build or transpilation step.
Complete source
import Message from 'js-message';
const outgoing = new Message({
type: 'user.updated',
data: {
id: 42,
active: true
}
});
console.log('object', outgoing.toJSON());
console.log('wire', outgoing.JSON);
const incoming = new Message(outgoing.JSON);
console.log('received', incoming.toJSON());What to inspect
toJSON()exposes the plain transport envelope.JSONemits the exact wire string.- The receiving constructor restores the same
typeanddata.