Bind C++ to JavaScript with no extra code. (WebAssembly & React Native)
MIT License
src/index.js
import { initCppJs } from './native/Factorial.h';
const { Factorial } = await initCppJs();
const factorial = new Factorial(99999);
const result = factorial.calculate();
console.log(result);
src/native/Factorial.h
class Factorial {
private:
int number;
public:
Factorial(int num) : number(num) {}
int calculate() {
if (number < 0) return -1;
int result = 1;
for (int i = 2; i <= number; i++) {
result *= i;
}
return result;
}
};
To begin building your project with Cpp.js, you’ll first need to install a few dependencies:
To set up a new cpp.js project with a minimal starter structure, execute the following command in your terminal:
npm create cpp.js@latest
Integrate cpp.js seamlessly into your existing projects using the appropriate packages for your development needs. Refer to the documentation links for detailed integration guides.
Platform | Package(s) | Documentation |
---|---|---|
Standalone | cpp.js | Learn |
Webpack | cppjs-webpack-plugin, cppjs-loader | Learn |
Rollup | rollup-plugin-cppjs | Learn |
Vite | vite-plugin-cppjs | Learn |
Rspack | cppjs-webpack-plugin, cppjs-loader | Learn |
Create React App (CRA) | cppjs-webpack-plugin, cppjs-loader | Learn |
React Native | cppjs-plugin-react-native, cppjs-plugin-react-native-ios-helper, cppjs-core-rn-embind | Learn |
Expo | cppjs-plugin-react-native, cppjs-plugin-react-native-ios-helper, cppjs-core-rn-embind | Learn |
Node.js | cpp.js | Learn |
Cloudflare Workers | cpp.js | Learn |
Copyright (c) 2024, Buğra Sarı