-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
44 lines (33 loc) · 1.23 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
var loaderUtils = require("loader-utils");
var path = require("path");
var ExternalModule = require("webpack/lib/ExternalModule");
module.exports = function(content) {
this.cacheable && this.cacheable();
if(!this.emitFile) throw new Error("emitFile is required from module system");
var query = loaderUtils.parseQuery(this.query);
var publicPath = query.publicPath || this.options.output.publicPath;
var libraryTarget = query.libraryTarget || this.options.output.libraryTarget;
if (query.name) {
var url = loaderUtils.interpolateName(this, query.name, {
context: query.context || this.options.context,
content: content,
regExp: query.regExp
});
this.emitFile(url, content);
var modulePath = loaderUtils.urlToRequest(path.join(publicPath, url));
} else {
var modulePath = this.resourcePath;
}
this.options.externals.push(modulePath);
if (!query.type) {
if (this.options.output.libraryTarget) {
query.type = this.options.output.libraryTarget;
} else {
throw new Error("No target type specified for external-loader");
}
}
var externalModule = new ExternalModule(modulePath, query.type);
var sourceAndMap = externalModule.source().sourceAndMap();
return sourceAndMap.source;
}
module.exports.raw = true;