-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wasm and text file support for local mode in
wrangler dev
(#334)
This adds support for `*.wasm` modules into local mode for `wrangler dev`. In 'edge' mode, we create a javascript bundle, but wasm modules are uploaded to the preview server directly when making the worker definition form upload. However, in 'local' mode, we need to have the actual modules available to the bundle. So we copy the files over to the bundle path. We also pass appropriate `--modules-rule` directive to `miniflare`. I also added a sample wasm app to use for testing, created from a default `workers-rs` project. Fixes #299
- Loading branch information
1 parent
c6f5f02
commit 536c7e5
Showing
10 changed files
with
795 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: wasm support for local mode in `wrangler dev` | ||
|
||
This adds support for `*.wasm` modules into local mode for `wrangler dev`. | ||
|
||
In 'edge' mode, we create a javascript bundle, but wasm modules are uploaded to the preview server directly when making the worker definition form upload. However, in 'local' mode, we need to have the actual modules available to the bundle. So we copy the files over to the bundle path. We also pass appropriate `--modules-rule` directive to `miniflare`. | ||
|
||
I also added a sample wasm app to use for testing, created from a default `workers-rs` project. | ||
|
||
Fixes https://github.com/cloudflare/wrangler2/issues/299 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## example-wasm-app | ||
|
||
This is a sample wasm worker. It was created by creating a [`workers-rs`](https://github.com/cloudflare/workers-rs) project, running a build, removing unneeded artifacts, and copying the output folder here. You can run this worker with `npx wrangler dev worker/shim.js` (or from the `wrangler` package directory with `npm start -- dev ../example-wasm-app/worker/shim.js`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "example-wasm-app", | ||
"version": "1.0.0", | ||
"module": "worker/shim.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as index_bg from "./index_bg.js"; | ||
import _wasm from "./index_bg.wasm"; | ||
|
||
const _wasm_memory = new WebAssembly.Memory({ initial: 512 }); | ||
let importsObject = { | ||
env: { memory: _wasm_memory }, | ||
"./index_bg.js": index_bg, | ||
}; | ||
|
||
export default new WebAssembly.Instance(_wasm, importsObject).exports; |
Oops, something went wrong.