forked from imba/imba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
47 lines (40 loc) · 1.01 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var compiler = require('./lib/compiler');
var helpers = require('./lib/compiler/helpers');
var path = require('path');
module.exports = function(content) {
this.cacheable();
var self = this;
var query = this.query;
var opts = {
filename: path.basename(this.resourcePath),
sourceMap: this.sourceMap,
sourcePath: this.resourcePath,
target: this.target,
comments: false,
ENV_DEBUG: this.debug,
ENV_WEBPACK: true
};
if(this.env){
opts.env = this.env;
}
if(query instanceof Object) {
Object.keys(query).forEach(function(key){
opts[key] = query[key];
});
}
try {
var result = compiler.compile(content, opts);
var js = result.toString();
if(result.warnings && true){
result.warnings.forEach(function(warn){
var msg = helpers.printWarning(result.source,warn);
var err = new Error(msg);
self.emitWarning(err);
});
}
this.callback(null, js, result.sourcemap);
} catch(e) {
var err = new Error(e.prettyMessage ? e.prettyMessage() : e.message);
this.emitError(err);
}
}