{"id":15065714,"url":"https://github.com/ushu/node-addon-loader","last_synced_at":"2025-10-05T02:31:26.223Z","repository":{"id":65424609,"uuid":"93046650","full_name":"ushu/node-addon-loader","owner":"ushu","description":"A loader for node native addons","archived":true,"fork":false,"pushed_at":"2018-06-11T09:58:06.000Z","size":10,"stargazers_count":17,"open_issues_count":4,"forks_count":26,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T14:42:24.428Z","etag":null,"topics":["nodejs","webpack","webpack-loader","webpack2"],"latest_commit_sha":null,"homepage":"https://github.com/ushu/node-addon-loader","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ushu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-01T10:40:36.000Z","updated_at":"2023-11-07T09:03:30.000Z","dependencies_parsed_at":"2023-01-23T01:55:12.256Z","dependency_job_id":null,"html_url":"https://github.com/ushu/node-addon-loader","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushu%2Fnode-addon-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushu%2Fnode-addon-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushu%2Fnode-addon-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ushu%2Fnode-addon-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ushu","download_url":"https://codeload.github.com/ushu/node-addon-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235356039,"owners_count":18976818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","webpack","webpack-loader","webpack2"],"created_at":"2024-09-25T00:46:12.064Z","updated_at":"2025-10-05T02:31:25.922Z","avatar_url":"https://github.com/ushu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A simple loader to embed native addons in [node] or [electron] projects.\n\nThis package is a mix between:\n\n- [node-loader] that loads a node module from an _absolute path_\n- [file-loader] that loads copy a file into the bundle and return its path\n\nThis one package allows to load a node native addon, binary file will end up copied into the output directory and loaded dynamically from its _relative_ path.\n\n## Install\n\nAdd the package to your `package.json`\n\n```bash\n$ yarn add --dev node-addon-loader\n```\n\n## Usage\n\nAdd the loader to your `webpack.config.js` for all `.node` native files.\n\n**webpack.config.js**\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.node$/,\n        use: 'node-addon-loader',\n        options: [\n          basePath: resolve(__dirname),\n        ]\n      }\n    ]\n  }\n}\n```\n\nNote the `basePath` option: it will instruct the loader of the \"base\" path, from where the [node] runtime will be started. It will generate loading path relative to this URL.\nFor example is you develop an [electron] app with a bundle emitted into `dist/` directory, you want all the required paths (emitted `require` statements) to be relative to the current directory of the [electron] runtime (they all will be like `dist/xxxx.node`).\n\n**In your application**\n\nYou require the file directly\n\n```js\nimport node from 'relative/path/to/myLib.node';\n// or\nconst node = require(\"relative/path/to/myLib.node\");\n```\n\nor with the inline syntax:\n\n**Inline**\n```js\nimport node from 'node-addon-loader!./myLib.node';\n```\n\n**with an alias**\n\na good option is to keep your modules in some place and create aliases for them, such as:\n\n```js\n// webpack config\nmodule.exports = {\n\n  resolve: {\n    alias: {\n    \"myLib\": \"/path/to/myLib.node\",\n    }\n  },\n\n  // ...\n\n}\n```\n\nand then use your alias directly:\n\n```js\nimport myLib from \"myLib\";\n```\n\n## Thanks\n\nbig thanks go the the authors of [node-loader] and [file-loader] which I eagerly copied.\n\n## TODO\n\nFix the issue with `emitFile`, see **TODO** in code.\n\nAll contributions are welcome, this is MIT do-whatever-you-want-I-dont-care code.\n\n[node]: https://nodejs.org\n[electron]: https://electron.atom.io/\n[node-loader]: https://github.com/webpack-contrib/node-loader/blob/master/index.js\n[file-loader]: https://github.com/webpack-contrib/file-loader \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fushu%2Fnode-addon-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fushu%2Fnode-addon-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fushu%2Fnode-addon-loader/lists"}