This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ff00b6
commit e7c8084
Showing
5 changed files
with
66 additions
and
7 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
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 @@ | ||
import("./src").then(module => { | ||
module.greet(); | ||
}); |
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,22 @@ | ||
extern crate cfg_if; | ||
extern crate wasm_bindgen; | ||
|
||
mod utils; | ||
|
||
use cfg_if::cfg_if; | ||
use wasm_bindgen::prelude::*; | ||
|
||
cfg_if! { | ||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | ||
// allocator. | ||
if #[cfg(feature = "wee_alloc")] { | ||
extern crate wee_alloc; | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn greet() -> String { | ||
"Hello, wasm-worker!".to_string() | ||
} |
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,17 @@ | ||
use cfg_if::cfg_if; | ||
|
||
cfg_if! { | ||
// When the `console_error_panic_hook` feature is enabled, we can call the | ||
// `set_panic_hook` function at least once during initialization, and then | ||
// we will get better error messages if our code ever panics. | ||
// | ||
// For more details see | ||
// https://github.com/rustwasm/console_error_panic_hook#readme | ||
if #[cfg(feature = "console_error_panic_hook")] { | ||
extern crate console_error_panic_hook; | ||
pub use self::console_error_panic_hook::set_once as set_panic_hook; | ||
} else { | ||
#[inline] | ||
pub fn set_panic_hook() {} | ||
} | ||
} |
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,12 @@ | ||
const path = require("path"); | ||
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); | ||
|
||
module.exports = { | ||
"entry": "./index.js", | ||
"target": "webworker", | ||
plugins: [ | ||
new WasmPackPlugin({ | ||
crateDirectory: path.resolve(__dirname, "src"), | ||
}), | ||
] | ||
} |