Skip to content

Cross Compile NPM modules

Jon Senra Dearle edited this page Oct 30, 2015 · 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

  • One pc with npm installed.

## Cross-compiling NPM modules
  • Firstly, we need to define some global variables like this:
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>
  • If all went file, you will have your npm module cross-compiled.
## Testing

Copy the npm module cross compiled 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.

Clone this wiki locally