C++ source (app.cpp):
#include <stdio.h>
#include <emscripten/bind.h>
using namespace emscripten;
float lerp(float a, float b, float t) {
return (1 - t) * a + t * b;
}
EMSCRIPTEN_BINDINGS(my_module) {
function("lerp", &lerp);
}
Perform command: emcc -lembind -o ../output/app.js app.cpp -s ENVIRONMENT=web
Then launch Webpack dev-server (entry point: bootstrap.js). bootstrap.js:
const app = require('./wasm/output/app.js');
And... how to use compiled code now? Official documentation examples show only <script> tag usage. It says, that code can be used as node module, but I didn't find any example.
console.log(app) displays Object. app.lerp(1, 2, 0.5) or Module.lerp(1, 2, 0.5) return app.lerp / Module.lerp is not a function. Tried to add export default Module to the end of compiled .js file and use as ES6 import(...), console.log(app) says that Module is a function.
Tried to add -s MODULARIZE=1 flag, the same result.
How to use compiled C++ via import or require?