Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Cross Compile NPM modules
How to cross compile NPM modules for OpenWRT
In this guide, we will explain how to compile npm modules for any cpu-architecture supported by node js.
We will use the OpenWRT Toolchain. Before continuing, I recommend reading these useful guides:
Listen Up! : Not all npm modules need to be cross compiled.## Prerequisites
You will need:
OpenWRT tool chain compiled according to your cpu architecture. If you haven't done yet. Go here
To have npm installed.
- Firstly, we need to define some global variables:
export CC=/route/to/openwrt/folder/staging_dir/toolchain-name-of-your-architecture-something/bin/your-architecture-gcc export CXX=/route/to/openwrt/folder/staging_dir/toolchain-name-of-your-architecture-something/bin/your-architecture-g++ export STAGING_DIR=/route/to/openwrt/folder/staging_dir
- Secondly, create a folder for your npm module and run:
cd folder_name npm --arch=<name> install <npm module>
Note: on some npm versions
--arch=<name>may change to
- If all went well, you will have your npm module cross-compiled.
Copy the cross compiled npm module to your device and create one app in order to test it.
If there are no errors, you have cross compiled your npm module successfully.