A Rollup plugin that extracts native .node files from the bundle and copies them to a specified directory, with options for renaming, mapping, and using dlopen or createRequire for ESM. Current stable version is 0.7.8. Released on npm, maintained by @danielgindi. Differentiates from other Rollup native module plugins by supporting node-pre-gyp and bindings integration, providing originTransform for dynamic path resolution, and offering flexible copying and naming via map functions.
npm install rollup-plugin-nativesVerified import paths — ran on the pinned version, not inferred.
Basic Rollup config that extracts native .node files to dist/libs and rewrites requires to point there.
Ensure all native module requires are static strings, or use originTransform to map dynamic paths.
Set destDir relative to the output file location (e.g., './libs' if bundle is in 'dist').
Set dlopen: true when working with .node files that have a different extension.
Set targetEsm: true when output format is 'esm' or 'es'.
Verify copyTo and destDir paths, ensure the plugin runs before bundle generation.
Set dlopen: false or ensure the module supports dlopen.