Skip to main content

Introduction

Cpp.js is a framework that provides the ability to use c++ code in the javascript ecosystem to help developers build applications for web and mobile platforms. Developers can integrate c++ libraries into their applications developed with javascript.

Here is a minimal example:

/src/main.js
import { initCppJs } './native/helloWorld.h';

const { getHelloWorldMessage } = await initCppJs();
console.log(getHelloWorldMessage());

/src/native/helloWorld.h
std::string getHelloWorldMessage() {
return 'Hello World!';
}

As shown in the example, the required header file is imported, and all functions and classes within this header can be accessed through the object returned by the initCppJs method.

Using Prebuilt Packages

Prebuilt packages can be used with cpp.js to avoid recompiling the package, thereby speeding up the overall application compilation.

Here is a minimal example:

/src/main.js
import { initCppJs } '@cpp.js/package-gdal/gdal.h';

const { Gdal } = await initCppJs();

You can view the prebuilt packages here.

Managing Bundle Size

Only the code referenced via the imported header is included in the final bundle. As a result, the bundle size is determined solely by the code that is actually used. For instance, if you only require a few methods from a large library, the bundle will include just the necessary code, not the entire library.

warning

Dead-code elimination is not implemented for Android.