Skip to content

Commit d7f6894

Browse files
authored
Merge pull request #32 from torch2424/iife-fix
Fixed IIFE Bundle Name, added IIFE Instructions to quickstart
2 parents f2c5d5c + 543227c commit d7f6894

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ export function myExportedFunctionThatTakesAString(value: string): string {
6565

6666
**2. In your Javascript**
6767

68-
In the browser using ESM Syntax:
68+
For **browser** JavaScript. We can do the following:
6969

7070
```javascript
71+
// If you are using a Javascript bundler, use the ESM bundle with import syntax
7172
import { AsBind } from "as-bind";
7273

74+
// If you are not using a bundler add a <script> tag to your HTML
75+
// Where the `src` points to the iife bundle (as-bind.iife.js), for example: https://unpkg.com/as-bind
76+
// Then, INSTEAD of using the import syntax, do: `const { AsBind } = AsBindIIFE;`
77+
7378
const wasm = fetch("./path-to-my-wasm.wasm");
7479

7580
const asyncTask = async () => {
@@ -84,7 +89,7 @@ const asyncTask = async () => {
8489
asyncTask();
8590
```
8691

87-
Or we can also use Node:
92+
For **Node** JavaScript, we would use the CommonJS bundle by do the following:
8893

8994
```javascript
9095
const { AsBind } = require("as-bind");

rollup.lib.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1-
import resolve from 'rollup-plugin-node-resolve';
2-
import commonjs from 'rollup-plugin-commonjs';
3-
import babel from 'rollup-plugin-babel';
4-
import json from 'rollup-plugin-json';
5-
import compiler from '@ampproject/rollup-plugin-closure-compiler';
6-
import bundleSize from 'rollup-plugin-bundle-size';
7-
import pkg from './package.json';
1+
import resolve from "rollup-plugin-node-resolve";
2+
import commonjs from "rollup-plugin-commonjs";
3+
import babel from "rollup-plugin-babel";
4+
import json from "rollup-plugin-json";
5+
import compiler from "@ampproject/rollup-plugin-closure-compiler";
6+
import bundleSize from "rollup-plugin-bundle-size";
7+
import pkg from "./package.json";
88

99
const sourcemapOption = process.env.PROD ? undefined : "inline";
1010

1111
const babelPluginConfig = {
1212
// so Rollup can convert unsupported es6 code to es5
13-
exclude: ['node_modules/**'],
13+
exclude: ["node_modules/**"],
1414
plugins: [
15-
['@babel/plugin-proposal-class-properties'],
16-
['@babel/plugin-proposal-object-rest-spread'],
15+
["@babel/plugin-proposal-class-properties"],
16+
["@babel/plugin-proposal-object-rest-spread"]
1717
]
1818
};
1919

20-
let plugins = [
21-
resolve(),
22-
commonjs(),
23-
json(),
24-
babel(babelPluginConfig)
25-
]
20+
let plugins = [resolve(), commonjs(), json(), babel(babelPluginConfig)];
2621

2722
if (process.env.PROD) {
28-
plugins = [
29-
...plugins,
30-
compiler(),
31-
bundleSize()
32-
]
23+
plugins = [...plugins, compiler(), bundleSize()];
3324
}
3425

35-
3626
const libBundles = [
3727
{
3828
input: "lib/lib.js",
@@ -64,7 +54,7 @@ const libBundles = [
6454
file: pkg.browser,
6555
format: "iife",
6656
sourcemap: sourcemapOption,
67-
name: "asbuild"
57+
name: "AsBindIIFE"
6858
},
6959
watch: {
7060
clearScreen: false

0 commit comments

Comments
 (0)