A webpack loader for bundling .node native addon files. Version 2.0.1 supports configuring output filename and path relative to webpack's output path. It is designed for Node.js or Electron main process targets. Unlike generic file loaders, it ensures .node binaries are emitted intact and correctly referenced in the bundle. Stable API with simple options: 'name' for filename template and 'from' for adjustment of relative path from output directory to emitted file. Last updated in 2021; low maintenance cadence.
npm install native-addon-loaderVerified import paths — ran on the pinned version, not inferred.
Shows how to configure native-addon-loader for a webpack build targeting Node.js, emitting .node files to a subdirectory with a content hash.
Use type: 'javascript/auto' in the rule to disable asset module handling for .node files.
No action needed; if using older version, upgrade to 2.x.
Set 'from' to the path where your JavaScript bundles are output relative to output.path (e.g., 'js').
Ensure the rule with native-addon-loader has test: /\.node$/ and no other loaders match .node files.
Check the 'name' option matches the require path in your code. Use name: '[name].[ext]' to keep the same filename.
Upgrade to webpack 4 or 5, or use native-addon-loader@1.x for webpack < 4.