{"action":"created","issue":{"url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/12","repository_url":"https://api.github.com/repos/webpack-contrib/node-loader","labels_url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/12/comments","events_url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/12/events","html_url":"https://github.com/webpack-contrib/node-loader/issues/12","id":259049007,"node_id":"MDU6SXNzdWUyNTkwNDkwMDc=","number":12,"title":"webpack build does not copy .node modules into the build folder and links via absolute path","user":{"login":"appdev44","id":32121156,"node_id":"MDQ6VXNlcjMyMTIxMTU2","avatar_url":"https://avatars0.githubusercontent.com/u/32121156?v=4","gravatar_id":"","url":"https://api.github.com/users/appdev44","html_url":"https://github.com/appdev44","followers_url":"https://api.github.com/users/appdev44/followers","following_url":"https://api.github.com/users/appdev44/following{/other_user}","gists_url":"https://api.github.com/users/appdev44/gists{/gist_id}","starred_url":"https://api.github.com/users/appdev44/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appdev44/subscriptions","organizations_url":"https://api.github.com/users/appdev44/orgs","repos_url":"https://api.github.com/users/appdev44/repos","events_url":"https://api.github.com/users/appdev44/events{/privacy}","received_events_url":"https://api.github.com/users/appdev44/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-09-20T06:02:00Z","updated_at":"2018-07-12T19:57:05Z","closed_at":null,"author_association":"NONE","body":"I have a webpack(3.5.6) project using node-loader(0.6.0), which I use to build a package for a nw.js application.\r\nI am trying to include a custom node package (Created with nw-gyp) in my build.\r\nBut for some reason all files apart from the \".node\" files are copied into my build folder, and in the generated java script file, it has an absolute path reference\r\neg\r\nfunction(module) {try {global.process.dlopen(module, \"c:\\\\src\\\\locale_modules\\\\helloworld.node\")\r\n\r\nthanks,\r\nalex"},"comment":{"url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/comments/404631907","html_url":"https://github.com/webpack-contrib/node-loader/issues/12#issuecomment-404631907","issue_url":"https://api.github.com/repos/webpack-contrib/node-loader/issues/12","id":404631907,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNDYzMTkwNw==","user":{"login":"Cellule","id":4157103,"node_id":"MDQ6VXNlcjQxNTcxMDM=","avatar_url":"https://avatars1.githubusercontent.com/u/4157103?v=4","gravatar_id":"","url":"https://api.github.com/users/Cellule","html_url":"https://github.com/Cellule","followers_url":"https://api.github.com/users/Cellule/followers","following_url":"https://api.github.com/users/Cellule/following{/other_user}","gists_url":"https://api.github.com/users/Cellule/gists{/gist_id}","starred_url":"https://api.github.com/users/Cellule/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cellule/subscriptions","organizations_url":"https://api.github.com/users/Cellule/orgs","repos_url":"https://api.github.com/users/Cellule/repos","events_url":"https://api.github.com/users/Cellule/events{/privacy}","received_events_url":"https://api.github.com/users/Cellule/received_events","type":"User","site_admin":false},"created_at":"2018-07-12T19:57:05Z","updated_at":"2018-07-12T19:57:05Z","author_association":"NONE","body":"I had a similar problem, I have a build machine that build my addon then webpack packs everything.\r\nHowever, since the .node file was actually bundled I couldn't run the packed script anywhere else.\r\n\r\nI ended up writing my own loader, I don't know if it can be made generic, but it does solves my problem at least and I hope it can help others.\r\n\r\n```js\r\nconst fs = require(\"fs\");\r\nconst path = require(\"path\");\r\n\r\nmodule.exports = function nodeLoader() {\r\n  const filename = path.basename(this.resourcePath);\r\n  const src = fs.readFileSync(this.resourcePath, {encoding: \"binary\"});\r\n  return `\r\nconst nodeFilename = ${JSON.stringify(filename)};\r\nconst src = ${JSON.stringify(src)};\r\nrequire(\"fs\").writeFileSync(nodeFilename, src, \"binary\");\r\ntry {\r\n  global.process.dlopen(\r\n    module,\r\n    nodeFilename\r\n  );\r\n} catch(e) {\r\n  throw new Error('node-loader: Cannot open ' + nodeFilename + ': ' + e);\r\n}\r\n`;\r\n};\r\n```\r\n\r\nIt will bundle the .node file as a string in the packed script and then can be used to load it.\r\nSince `global.process.dlopen` expects a filename, I had to write the data to a file in `cwd` before loading it\r\n"}}
{"actor":{"display_login":"Cellule"}}