Import native code with Rollup
npm install rollup-plugin-native




Import native code with Rollup.
As there is currently no support for
``js`
import {x} from "module.node"
`bash`
npm install --save-dev rollup-plugin-native
`js
// rollup.config.js
import native from 'rollup-plugin-native';
export default {
input: 'src/main.js',
output: {
file: 'public/bundle.js',
format: 'cfs'
},
plugins: [
native({
platformName: "${dirname}/precompiled/${nodePlatform}-${nodeArchitecture}/node.napi.node",
//platformName: "${dirname}/${basename}-${nativePlatform}-${nativeArchitecture}.node",
})
]
}
`
`js
import { funcA, constB } from "../module.node";
funcA(); // native call
``
will generate a dlopen / require for
"../precompiled/linux-x86/node.napi.node"
Substitution properties in the platformName
- dirname dirname
- basename basename (.node stiped away)
- nodePlatform from process.platform()
- nodeArchitecture from process.arch()
- nativePlatform as given from uname
- nativeArchitecture as used in llvm & gcc
BSD