Cross Compile NPM modules

Jesús Darío edited this page Feb 9, 2017 · 5 revisions

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:

Cross Compile Nodejs

What is Cross-Compilation?

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.

## Cross-compiling NPM modules
  • 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 --target_arch=<name>

  • If all went well, you will have your npm module cross-compiled.
## Testing

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.