forked from petehunt/jsx-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 965 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
var reactTools = require('react-tools');
var loaderUtils = require('loader-utils');
module.exports = function(source) {
this.cacheable && this.cacheable();
var sourceFilename = loaderUtils.getRemainingRequest(this);
if (/\.js/.test(sourceFilename) && source.indexOf('/** @jsx React') === -1) {
return this.callback(null, source);
}
var current = loaderUtils.getCurrentRequest(this);
var query = loaderUtils.parseQuery(this.query);
if (query.insertPragma) {
source = '/** @jsx ' + query.insertPragma + ' */' + source;
}
var transform = reactTools.transformWithDetails(source, {
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);
};