diff --git a/template/Cargo.toml b/template/Cargo.toml index 71d764c..93b9c3d 100644 --- a/template/Cargo.toml +++ b/template/Cargo.toml @@ -17,8 +17,12 @@ crate-type = ["cdylib"] lto = true [features] -# If you uncomment this line, it will enable `wee_alloc`: -#default = ["wee_alloc"] +default = [ + # If you uncomment this line, it will enable `wee_alloc`: + # "wee_alloc", + # If you uncomment this line, it will enable `console_error_panic_hook`: + # "console_error_panic_hook" +] [dependencies] # The `wasm-bindgen` crate provides the bare minimum functionality needed @@ -30,19 +34,18 @@ wasm-bindgen = "0.2.45" # allocator, so it's not enabled by default. wee_alloc = { version = "0.4.2", optional = true } +# The `console_error_panic_hook` crate provides better debugging of panics by +# logging them with `console.error`. This is great for development, but requires +# all the `std::fmt` and `std::panicking` infrastructure, so it should only be +# enabled in debug mode. +console_error_panic_hook = { version ="0.1.5", optional = true } + # The `web-sys` crate allows you to interact with the various browser APIs, # like the DOM. [dependencies.web-sys] version = "0.3.22" features = ["console"] -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so it's only enabled -# in debug mode. -[target."cfg(debug_assertions)".dependencies] -console_error_panic_hook = "0.1.5" - # These crates are used for running unit tests. [dev-dependencies] wasm-bindgen-test = "0.2.45" diff --git a/template/src/lib.rs b/template/src/lib.rs index a649970..8b581ad 100644 --- a/template/src/lib.rs +++ b/template/src/lib.rs @@ -15,8 +15,8 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; #[wasm_bindgen(start)] pub fn main_js() -> Result<(), JsValue> { // This provides better error messages in debug mode. - // It's disabled in release mode so it doesn't bloat up the file size. - #[cfg(debug_assertions)] + // It should be disabled in release mode so it doesn't bloat up the file size. + #[cfg(feature = "console_error_panic_hook")] console_error_panic_hook::set_once();