-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
29 lines (28 loc) · 1008 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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var Utils = require("loader-utils");
var FOOTER = "/*** EXPORTS FROM ng-loader ***/\n";
module.exports = function(content, sourceMap) {
if(this.cacheable) this.cacheable();
var query = Utils.parseQuery(this.query);
var exports = [];
var keys = Object.keys(query);
if (keys.length == 1) {
exports.push("module.exports = window.angular.module('" + keys[0] + "');");
}
if(sourceMap) {
var currentRequest = Utils.getCurrentRequest(this);
var node = SourceNode.fromStringWithSourceMap(content, new SourceMapConsumer(sourceMap));
node.add("\n\n" + FOOTER + exports.join("\n"));
var result = node.toStringWithSourceMap({
file: currentRequest
});
this.callback(null, result.code, result.map.toJSON());
return;
}
return content + "\n\n" + FOOTER + exports.join("\n");
};