Code Monkey home page Code Monkey logo

prebuildify's Introduction

prebuildify

Create and package prebuilds for native modules

npm install -g prebuildify

Usage

First go to your native module and make a bunch of prebuilds

# got to your native module
cd your-native-module
# build for all electron/node binary versions and strip out symbols
prebuildify --all --strip
# the prebuilds will be stored in ./prebuilds
ls prebuilds

If your module is using the new node core N-API, then you can prebuild using the --napi flag

# prebuild for n-api
prebuildify --napi

Then only remaining thing you need to do now is make your module use a prebuild if one exists for the platform/runtime you are using.

Use node-gyp-build to do this.

# first install node-gyp-build
npm install --save node-gyp-build

Then add node-gyp-build as an install script to your module's package.json

{
  "name": "your-native-module",
  "scripts": {
    "install": "node-gyp-build"
  }
}

The install script will check if a compatible prebuild is bundled. If so it does nothing. If not it will run node-gyp rebuild to produce a build. This means that if the user using your module has disabled install scripts your module will still work (!) as long as a compatible prebuild is bundled.

When loading your native binding from your index.js you should use node-gyp-build as will to make sure to get the right binding

// Will load a compiled build if present or a prebuild.
// If no build if found it will throw an exception
var binding = require('node-gyp-build')(__dirname)

module.exports = binding

An added benefit of this approach is that your native modules will work across multiple node and electron versions without having the user need to reinstall or recompile them - as long as you produce prebuilds for all versions.

When publishing your module to npm remember to include the ./prebuilds folder.

That's it! Happy native hacking.

License

MIT

prebuildify's People

Contributors

mafintosh avatar fanatid avatar emilbayes avatar g-ray avatar jimpick avatar ralphtheninja avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.