nshen / vite-plugin-wasm-pack

🦀 Vite plugin for rust wasm-pack
MIT License
234 stars 36 forks source link

Inline js support #11

Open hanabi1224 opened 2 years ago

hanabi1224 commented 2 years ago

It looks like the plugin cannot properly bundle inlinejs, is there plan to support that?

Add below code to example/my-crate/src/lib.rs, then the build will fail

#[wasm_bindgen(inline_js = "export function alert2(msg) { alert(msg) }")]
extern "C" {
    fn alert2(s: &str);
}

#[wasm_bindgen]
pub fn greet2(name: &str) {
    alert2(&format!("Hello from js via rs,{}!", name));
}
Yongle-Fu commented 1 year ago

emcc support hope also. build by follow command

emcc -O3 -s WASM=1 \
    -s ASSERTIONS=1 \
    -s MODULARIZE=1 \
    -s ALLOW_MEMORY_GROWTH=1 \
    -s NODEJS_CATCH_EXIT=0 \
    -s NODEJS_CATCH_REJECTION=0 \
    -s EXPORT_NAME='XXXSDK' \
    -s EXPORTED_RUNTIME_METHODS='["cwrap"]' \
    -s LLD_REPORT_UNDEFINED \
    ./build/lib_xxx.a \
    main.cpp \
    --post-js glue.js \
    -o ./dist/xxxx.js