-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathindex.js
28 lines (24 loc) · 855 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
var jstransform = require('jstransform/simple');
var loaderUtils = require('loader-utils');
module.exports = function(source) {
this.cacheable && this.cacheable();
var sourceFilename = loaderUtils.getRemainingRequest(this);
var current = loaderUtils.getCurrentRequest(this);
var query = loaderUtils.parseQuery(this.query);
if (query.insertPragma) {
source = '/** @jsx ' + query.insertPragma + ' */' + source;
}
var transform = jstransform.transform(source, {
react: true,
harmony: query.harmony,
stripTypes: query.stripTypes,
es5: query.es5,
sourceMap: this.sourceMap
});
if (transform.sourceMap) {
transform.sourceMap.sources = [sourceFilename];
transform.sourceMap.file = current;
transform.sourceMap.sourcesContent = [source];
}
this.callback(null, transform.code, transform.sourceMap);
};