-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (35 loc) · 933 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
32
33
34
35
36
37
'use strict';
var through = require('through2');
var path = require('path');
var convert = require('convert-source-map');
var reactHotLoader = require('react-hot-loader');
module.exports = function(file, opts) {
var pieces = [];
return through.obj(function(row, enc, next) {
pieces.push(row);
next();
}, function(done) {
var self = this;
var source = pieces.join('');
var inputMapCV = convert.fromSource(source);
var inputMap;
if (inputMapCV) {
inputMap = inputMapCV.toObject();
source = convert.removeComments(source);
}
reactHotLoader.call({
resourcePath: file,
callback: function(err, source, map) {
if (err) {
done(err);
} else {
if (map) {
source = source + '\n' + convert.fromJSON(map).toComment();
}
self.push(source);
done();
}
}
}, source, inputMap);
});
};