Skip to content

Commit 8ba2bc0

Browse files
committed
Add documentation on using the optional platform-specific packages
1 parent 1402100 commit 8ba2bc0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ module.exports = binding
7171
An added benefit of this approach is that your native modules will work across multiple node and electron versions without having the user
7272
need to reinstall or recompile them - as long as you produce prebuilds for all versions. With Node-API you only have to produce prebuilds for every runtime.
7373

74-
When publishing your module to npm remember to include the `./prebuilds` folder.
74+
75+
## Platform-specific Packages
76+
As an alternate to including all prebuilds directly in your published package, you can use `--optional-packages` to setup the prebuilds for publishing as separate platform-specific packages. Using this option, each prebuild directory will also include a package.json that specifies the target platform and architectures along with some basic package files. Each of these prebuild directories can then be published as separate packages in NPM. In addition,
77+
the main package should specify all the platform packages as `optionalDependencies`. When installed, NPM (or Yarn, etc.) will then only install the optional dependency with the platform/architecture matching the target machine.
78+
79+
This provides both the efficiency of only needing to download/install the binary (or binaries) needed for the current platform, but also the key benefit of the prebuildify system in that binaries are downloaded and available as part of the normal NPM install process (no install scripts for extra downloads are necessary). When using this method, you should omit the prebuilds folder when publishing your package (since they will be separately downloaded).
80+
81+
If you do not use this option, when publishing your module to npm, remember to include the `./prebuilds` folder.
7582

7683
That's it! Happy native hacking.
7784

@@ -94,6 +101,7 @@ Options can be provided via (in order of precedence) the programmatic API, the C
94101
| `--tag-uv` | - | `false` | Tag prebuild with `uv`\*\*\*
95102
| `--tag-armv` | - | `false` | Tag prebuild with `armv`\*\*\*
96103
| `--tag-libc` | - | `false` | Tag prebuild with `libc`\*\*\*
104+
| `--optional-dependencies`| - | `false` | Add package.json and basic files for package publishing
97105
| `--preinstall` | - | - | Command to run before build
98106
| `--postinstall` | - | - | Command to run after build
99107
| `--shell` | `PREBUILD_SHELL` | `'sh'` on Android | Shell to spawn commands in

0 commit comments

Comments
 (0)