If you use a library it's not harder. In Rust you would use something like this, https://crates.io/crates/wasm-encoder
While in JS you would probably use https://www.npmjs.com/package/binaryen