Extract native modules (.node files) while creating a rollup bundle and put them in one place"
npm install --save-dev rollup-plugin-natives
In some cases you have native dependencies, maybe require by bindings
or node-pre-gyp
,
and you have to put them somewhere accessile to the rolled-up bundle.
This package is just for doing exactly this.
// rollup.config.js
import nativePlugin from 'rollup-plugin-natives';
export default {
input: 'main.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
nativePlugin({
// Where we want to physically put the extracted .node files
copyTo: 'dist/libs',
// Path to the same folder, relative to the output bundle js
destDir: './libs',
// Use `dlopen` instead of `require`/`import`.
// This must be set to true if using a different file extension that '.node'
dlopen: false,
// Modify the final filename for specific modules
// Receives a full path to the original file, and returns a desired filename
map: modulePath => 'filename.node',
// Or you can return a desired file name and a specific destination to copy to
map: modulePath => { name: 'filename.node', copyTo: 'C:\\Dist\\libs\\filename.node' },
})
]
};
MIT
This plugin was created by me and shared with you courtesy of Silverbolt which I'm working for.