Sha256: d5f4d830c316a91e951cdaeab5cb23ae47dbc910b05de849e67bef1ea709564f

Contents?: true

Size: 1.38 KB

Versions: 30

Compression:

Stored size: 1.38 KB

Contents

# Hello, World!

[View full source code][code] or [view the compiled example online][online]

[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/hello_world/
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/hello_world

This is the "Hello, world!" example of `#[wasm_bindgen]` showing how to set up
a project, export a function to JS, call it from JS, and then call the `alert`
function in Rust.

## `Cargo.toml`

The `Cargo.toml` lists the `wasm-bindgen` crate as a dependency.

Also of note is the `crate-type = ["cdylib"]` which is largely used for wasm
final artifacts today.

```toml
{{#include ../../../examples/hello_world/Cargo.toml}}
```

## `src/lib.rs`

Here we define our Rust entry point along with calling the `alert` function.

```rust
{{#include ../../../examples/hello_world/src/lib.rs}}
```

## `index.js`

Our JS entry point is quite small!

```js
{{#include ../../../examples/hello_world/index.js}}
```

## Webpack-specific files

> **Note**: Webpack is required for this example, and if you're interested
> in options that don't use a JS bundler [see other examples][wab].

[wab]: without-a-bundler.html

And finally here's the Webpack configuration and `package.json` for this
project:

**webpack.config.js**

```js
{{#include ../../../examples/hello_world/webpack.config.js}}
```

**package.json**

```json
{{#include ../../../examples/hello_world/package.json}}
```

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-22.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-21.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-20.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-20.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-18.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-17.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-17.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-16.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-15.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-15.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/examples/hello-world.md
wasmtime-14.0.4 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-14.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-14.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-14.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-13.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-12.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-12.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-11.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md
wasmtime-10.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/examples/hello-world.md