parcel-plugin-emscripten
v0.2.0
Published
Plugin
Downloads
3
Readme
Parcel plugin for Emscripten
A Parcel plugin to enable importing a C(++) file inside a JS file.
Emscripten has to be installed and emcc
needs to be in PATH
.
Example:
import Module from './test.c';
const Instance = Module();
Instance.then(()=>{
console.log(Instance._add(10,20));
});
// equivalent to
Instance.then((v)=>{
console.log(v._add(10,20));
});
//test.c
#include <emscripten.h>
int EMSCRIPTEN_KEEPALIVE add(int x, int y) {
return x + y;
}
For more complex examples, see the example directory.
Instance.then
is quite fragile and not a thenable, see https://github.com/kripken/emscripten/issues/5820
Using multiple Modules (= importing multiple C files) is supported, but it isn't very filesize efficient. Consider writing a single C-wrapper and importing that instead!
To pass additional arguments to emcc
(change optimization, link another C file or a library, ...), specify them in the first line of your main C file: (this would disable optimizations and compile and link lib.c
as well)
//parcel: -O0 lib.c
#include ...