Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hello world tutorial section to better reflect the current state of the templates and tooling. #238

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions src/game-of-life/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Make sure you have followed the [setup instructions](setup.html) before beginnin
The project template comes pre-configured with sane defaults, so you can quickly
build, integrate, and package your code for the Web.

### Using `cargo-generate`

Clone the project template with this command:

```text
Expand All @@ -23,6 +25,20 @@ This should prompt you for the new project's name. We will use
wasm-game-of-life
```

### Using `wasm-pack`

You can also use `wasm-pack` to clone the template with this command, replacing `name` with the new project's name:

```text
wasm-pack new name
```

In this case, we will use **"wasm-game-of-life"**:

```text
wasm-pack new wasm-game-of-life
```

## What's Inside

Enter the new `wasm-game-of-life` project
Expand All @@ -39,9 +55,11 @@ wasm-game-of-life/
├── LICENSE_APACHE
├── LICENSE_MIT
├── README.md
└── src
├── lib.rs
└── utils.rs
├── src
│   ├── lib.rs
│   └── utils.rs
└── tests
└── web.rs
```

Let's take a look at a couple of these files in detail.
Expand Down Expand Up @@ -103,7 +121,7 @@ To do all of that, run this command inside the project directory:

```
wasm-pack build
```
``

When the build has completed, we can find its artifacts in the `pkg` directory,
and it should have these contents:
Expand All @@ -112,6 +130,8 @@ and it should have these contents:
pkg/
├── package.json
├── README.md
├── wasm_game_of_life_bg.d.ts
├── wasm_game_of_life_bg.js
├── wasm_game_of_life_bg.wasm
├── wasm_game_of_life.d.ts
└── wasm_game_of_life.js
Expand All @@ -138,7 +158,7 @@ interesting values back and forth between wasm and JavaScript, it will help
shepherd those values across the boundary.

```js
import * as wasm from './wasm_game_of_life_bg';
import * as wasm from './wasm_game_of_life_bg.wasm';

// ...

Expand Down Expand Up @@ -174,16 +194,15 @@ publish our package to npm.
"collaborators": [
"Your Name <[email protected]>"
],
"description": null,
"version": "0.1.0",
"license": null,
"repository": null,
"files": [
"wasm_game_of_life_bg.wasm",
"wasm_game_of_life.js",
"wasm_game_of_life.d.ts"
],
"main": "wasm_game_of_life.js",
"types": "wasm_game_of_life.d.ts"
"module": "wasm_game_of_life.js",
"types": "wasm_game_of_life.d.ts",
"sideEffects": false
}
```

Expand Down Expand Up @@ -212,6 +231,7 @@ wasm-game-of-life/www/
├── LICENSE-APACHE
├── LICENSE-MIT
├── package.json
├── package-lock.json
├── README.md
└── webpack.config.js
```
Expand Down Expand Up @@ -243,6 +263,7 @@ load `bootstrap.js`, which is a very thin wrapper around `index.js`.
<title>Hello wasm-pack!</title>
</head>
<body>
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
<script src="./bootstrap.js"></script>
</body>
</html>
Expand Down Expand Up @@ -278,7 +299,7 @@ JavaScript bundler and its development server.
> is just the bundler and development server we've chosen for convenience
> here. Parcel and Rollup should also support importing WebAssembly as
> ECMAScript modules. You can also use Rust and WebAssembly [without a
> bundler][] if you prefer!
> bundler] if you prefer!

[without a bundler]: https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html

Expand Down Expand Up @@ -312,6 +333,18 @@ import * as wasm from "wasm-game-of-life";
wasm.greet();
```

Next, remove `hello-wasm-pack` from the `"devDependencies"` section.
This doesn't really matter too much in the end, but it can decrease build times slightly.
```js
{
// ...
"devDependencies": {
"hello-wasm-pack": "^0.1.0", // Remove this line!
//...
}
}
```

Since we declared a new dependency, we need to install it:
```text
npm install
Expand Down