-
Notifications
You must be signed in to change notification settings - Fork 233
/
node-loader.js
31 lines (26 loc) · 986 Bytes
/
node-loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Webpack is a bit of a nightmare when dealing with binary node modules.
This replaces the existing functionality with something that seems to work
better.
*/
const { getOptions, interpolateName } = require('loader-utils');
const path = require('path');
module.exports = function loader(content) {
const options = getOptions(this);
const name = interpolateName(
this,
typeof options.name !== 'undefined' ? options.name : '[name].[ext]',
{
context: this.rootContext,
content,
}
);
const compiler = this._compiler;
const outputPath = compiler.options.output.path;
const fullPath = path.join(outputPath, name);
if (this.mode == "development") {
return `module.exports = __non_webpack_require__(String.raw\`${fullPath}\`);`
} else {
return `process.dlopen(module, __dirname + require("path").sep + '${options.publicPath}' + require("path").sep + '${name}');`
}
}