So we got nexe to compile nodejs projects to an executable binary:
- it downloads the nodejs source
- it creates a single file nodejs source (using sardines )
- it monkey patches the nodejs code to include this single file in the binary (adding it to the lib/nexe.js)
$ nexe -i myproject.js -o myproject.bin -r 0.10.3
Caveats:
- I had an issue with unicode chars that got converted: it uses uglify.js and this needs to be configured to leave them alone Sardines Patch Unichode . This was necessary to get terminal.js to compile
- Next issue was to get socket.io-client to compile: the swfobject has document and navigator objects, so this had to be fixed as well - Sardines Patch Document & Navigator
Alternatives:
- Node-webkit to package stuff
- http://tidesdk.multipart.net/docs/user-dev/generated/
- nexe doesn't handle native modules (yet).
This is what I did to add the pty.js native module directly to the nodejs binary
$ tar -xzvf node-v0.8.21.tar.gz
$ cd node-v0.8.21
# Copy the native code
$ cp ~/dev/terminal.js/node_modules/pty.js/src/unix/pty.cc src/node_pty.cc
# Correct the export name of the module
# Add the node_ prefix to the node_module name
# Last line should read - NODE_MODULE(node_pty, init)
# add node_pty to src/node_extensions.h (f.e. right after node_zlib)
# NODE_EXT_LIST_ITEM(node_pty)
# Copy the pty.js file
$ cp ~/dev/pty.js/lib/pty.js lib/pty.js
# Adapt the namings/bindings in lib/pty.js
# 1) replace: var pty = require('../build/Release/pty.node');
# with: var binding = process.binding('pty');
# 2) replace all references to pty. to binding.
$ ./configure
$ make
Now you have a custom build node in out/Release/node The filesize was about 10034856 , you can further strip it and 6971192 (6.6M)
Info on the process.binding:
- http://blog.carbonfive.com/2011/03/14/node-js-part-ii-spelunking-in-the-code/
- https://groups.google.com/forum/?fromgroups#!topic/nodejs/R5fDzBr0eEk
- this also make it easy to make a curl installer from it as it only requires you to download file
- create a rpm, deb, etc.. package from it using fpm
- or create a native MacOSX .app file from it as Matthias Bynens suggest in http://mathiasbynens.be/notes/shell-script-mac-apps
- https://github.com/subtleGradient/Appify-UI
- http://blog.coolaj86.com/articles/how-to-create-an-osx-pkg-installer.html
Once you have compiled node with the native modules embedded, how do you point nexe to use it for compiling with your actual application?