esbuild-plugin-native-modules
Prevents bundling packages that use platform-specific binaries (.node .dll .dylib .so .so1 etc).
Internally, it copies specified packages traversing symlinks (which would play well with pnpm and workspaces) so the output looks like that:
app
├─── node_modules
│ ├─── sharp
│ │ └─── ...
│ └─── fsevents
│ └─── ...
└─── index.js
Usage:
const natives = require('esbuild-plugin-native-modules');
const esbuild = require('esbuild');
const path = require('path');
(async function () {
console.time('Done');
await esbuild.build({
bundle: true,
entryPoints: [path.resolve(__dirname, '../index.js')],
allowOverwrite: true,
outfile: path.resolve(__dirname, `../build/index.js`),
target: 'es2019',
platform: 'node',
plugins: [natives(['sharp', 'fsevents'])],
});
console.timeEnd('Done');
})();