forked from toyobayashi/native-addon-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (27 loc) · 936 Bytes
/
index.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
32
const loaderUtils = require('loader-utils')
const path = require('path')
const schema = require('./options.json')
module.exports = function (content) {
const loaderOptions = this.getOptions(schema) || {}
const from = loaderOptions.from || '.'
const name = loaderUtils.interpolateName(
this,
typeof loaderOptions.name !== 'undefined' ? loaderOptions.name : '[name].[ext]',
{
context: this.rootContext,
content,
}
);
let requirePath = path.posix.relative(from, name)
if (requirePath[0] !== '.') {
requirePath = './' + requirePath
}
if (typeof this.emitFile === 'function') {
this.emitFile(name, content, false);
this.addDependency(this.resourcePath);
} else {
throw new Error('emitFile function is not available');
}
return `process.dlopen(module, ${JSON.stringify(this.utils.contextify(this.context || this.rootContext, requirePath))});`
}
module.exports.raw = true