Skip to content

Commit 883cae2

Browse files
Merge pull request #216 from csmoe/build
Split init into init and build
2 parents 425aefb + 3bccad9 commit 883cae2

File tree

9 files changed

+213
-230
lines changed

9 files changed

+213
-230
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ visiting that repo!
2929

3030
## 🎙️ Commands
3131

32+
- [`init`](docs/init.md): [**Deprecated**] Initialize an npm wasm pkg from a rustwasm crate
33+
- [`build`](docs/build.md): Generate an npm wasm pkg from a rustwasm crate
3234
- [`init`](docs/init.md): Generate an npm wasm pkg from a rustwasm crate
33-
- [`pack`](docs/pack-and-publish.md): Create a tarball of your rustwasm pkg
34-
- [`publish`](docs/publish.md): Publish your rustwasm pkg to a registry
35+
- [`pack` and `publish`](docs/pack-and-publish.md): Create a tarball of your rustwasm pkg and/or publish to a registry
3536

3637
## 📝 Logging
3738

@@ -89,7 +90,7 @@ check out our [contribution policy].
8990
```
9091

9192
5. Install this tool: `cargo install wasm-pack`
92-
6. Run `wasm-pack init`, optionally, pass a path to a dir or a scope (see above for details)
93+
6. Run `wasm-pack build`, optionally, pass a path to a dir or a scope (see above for details)
9394
7. This tool generates files in a `pkg` dir
9495
8. To publish to npm, run `wasm-pack publish`. You may need to login to the
9596
registry you want to publish to. You can login using `wasm-pack login`.

docs/build.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# wasm-pack build
2+
3+
The `wasm-pack build` command creates the files neccessary for JavaScript
4+
interoperability and for publishing a package to npm. This involves compiling
5+
your code to wasm and generating a pkg folder. This pkg folder will contain the
6+
wasm binary, a JS wrapper file, your `README`, and a `package.json` file.
7+
8+
## Path
9+
10+
The `wasm-pack build` command can be given an optional path argument, e.g.:
11+
12+
```
13+
wasm-pack build examples/js-hello-world
14+
```
15+
16+
This path should point to a directory that contains a `Cargo.toml` file. If no
17+
path is given, the `build` command will run in the current directory.
18+
19+
## Debug
20+
21+
The init command accepts an optional `--debug` argument. This will build the
22+
output package using cargo's
23+
[default non-release profile][cargo-profile-sections-documentation]. Building
24+
this way is faster but applies few optimizations to the output, and enables
25+
debug assertions and other runtime correctness checks.
26+
27+
The exact meaning of this flag may evolve as the platform matures.
28+
29+
[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections
30+
31+
## Target
32+
33+
The `build` command accepts a `--target` argument. This will customize the output files
34+
to align with a particular type of JS module. This allows wasm-pack to generate either
35+
ES6 modules or CommonJS modules for use in browser and in NodeJS. Defaults to `browser`.
36+
The options are:
37+
38+
```
39+
wasm-pack build --target nodejs
40+
```
41+
42+
| Option | Description |
43+
|-----------|-----------------------------------------------------------------------------------------------------------------|
44+
| `nodejs` | Outputs JS that uses CommonJS modules, for use with a `require` statement. |
45+
| `browser` | Outputs JS that uses ES6 modules, primarily for use with `import` statements and/or bundlers such as `webpack`. |
46+
47+
## Scope
48+
49+
The init command also accepts an optional `--scope` argument. This will scope
50+
your package name, which is useful if your package name might conflict with
51+
something in the public registry. For example:
52+
53+
```
54+
wasm-pack build examples/js-hello-world --scope test
55+
```
56+
57+
This command would create a `package.json` file for a package called
58+
`@test/js-hello-world`. For more information about scoping, you can refer to
59+
the npm documentation [here][npm-scope-documentation].
60+
61+
[npm-scope-documentation]: https://docs.npmjs.com/misc/scope
62+
63+
## Mode
64+
65+
The `build` command accepts an optional `--mode` argument.
66+
```
67+
wasm-pack build examples/js-hello-world --mode no-install
68+
```
69+
70+
| Option | Description |
71+
|---------------|------------------------------------------------------------------------------------------|
72+
| `no-install` | `wasm-pack init` implicitly and create wasm binding without installing `wasm-bindgen`. |
73+
| `normal` | do all the stuffs of `no-install` with installed `wasm-bindgen`. |

docs/init.md

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# wasm-pack init
1+
# wasm-pack init(Deprecated)
22

33
The `wasm-pack init` command creates the files neccessary for JavaScript
4-
interoperability and for publishing a package to npm. This involves compiling
5-
your code to wasm and generating a pkg folder. This pkg folder will contain the
6-
wasm binary, a JS wrapper file, your `README`, and a `package.json` file.
4+
interoperability and for publishing a package to npm. This involves
5+
generating a pkg folder. This pkg folder will contain the
6+
`README` and a `package.json` file.
77

88
## Path
99

@@ -46,27 +46,4 @@ This command would create a `package.json` file for a package called
4646
`@test/js-hello-world`. For more information about scoping, you can refer to
4747
the npm documentation [here][npm-scope-documentation].
4848

49-
## Debug
50-
51-
The init command accepts an optional `--debug` argument. This will build the
52-
output package using cargo's
53-
[default non-release profile][cargo-profile-sections-documentation]. Building
54-
this way is faster but applies few optimizations to the output, and enables
55-
debug assertions and other runtime correctness checks.
56-
57-
The exact meaning of this flag may evolve as the platform matures.
58-
59-
[npm-scope-documentation]: https://docs.npmjs.com/misc/scope
60-
[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections
61-
62-
## Skipping build
63-
64-
The init command accepts an optional `--skip-build` argument.
65-
66-
This will deactivate those steps:
67-
- installing wasm target (via cargo)
68-
- compiling the code to wasm
69-
- installing wasm-bindgen (via rustup)
70-
- running wasm-bindgen on the built wasm
71-
72-
Basically it will remains only the steps that update the metadata of `package.json`.
49+
[npm-scope-documentation]: https://docs.npmjs.com/misc/scope

0 commit comments

Comments
 (0)