Skip to content

Commit 095dfd9

Browse files
committed
fix AMD-style modules; add amd-example.html for testing
1 parent 4c1ee63 commit 095dfd9

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

example/amd-example.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../dist.es5/msgpack.min.js"></script>
5+
<script>
6+
console.log(MessagePack);
7+
</script>
8+
<style>
9+
main {
10+
width: 80%;
11+
margin: 20px auto;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<main>
17+
<h1>AMD for @msgpack/msgpack</h1>
18+
<pre><code>&lt;script src="https://unpkg.com/@msgpack/msgpack"&gt;&lt;/script&gt;
19+
</code></pre>
20+
21+
<script src="./amd-example.js"></script>
22+
</main>
23+
</body>
24+
</html>

example/amd-example.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable no-console */
2+
"use strict";
3+
4+
try {
5+
const object = {
6+
nil: null,
7+
integer: 1,
8+
float: Math.PI,
9+
string: "Hello, world!",
10+
binary: Uint8Array.from([1, 2, 3]),
11+
array: [10, 20, 30],
12+
map: { foo: "bar" },
13+
timestampExt: new Date(),
14+
};
15+
16+
document.writeln("<p>input:</p>");
17+
document.writeln(`<pre><code>${JSON.stringify(object, undefined, 2)}</code></pre>`);
18+
19+
const encoded = MessagePack.encode(object);
20+
21+
document.writeln("<p>output:</p>");
22+
document.writeln(`<pre><code>${JSON.stringify(MessagePack.decode(encoded), undefined, 2)}</code></pre>`);
23+
} catch (e) {
24+
console.error(e);
25+
document.write(`<p style="color: red">${e.constructor.name}: ${e.message}</p>`);
26+
}

webpack.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const config = {
1212
entry: "./src/index.ts",
1313
output: {
1414
path: path.resolve(__dirname, "dist.es5"),
15+
library: "MessagePack",
1516
libraryTarget: "umd",
1617
globalObject: "this",
1718
},
@@ -37,6 +38,7 @@ const config = {
3738
new webpack.DefinePlugin({
3839
"process.env.WASM": JSON.stringify(null), // use only MSGPACK_WASM
3940
"process.env.TEXT_ENCODING": JSON.stringify("null"),
41+
"process.env.TEXT_DECODER": JSON.stringify(null),
4042
}),
4143
],
4244
externals: {

0 commit comments

Comments
 (0)