-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.js
37 lines (29 loc) · 913 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
var fs = require('fs');
var jstransform = require('jstransform/simple');
var installed = false;
function install(options) {
if (installed) {
return;
}
options = options || {};
// Import everything in the transformer codepath before we add the import hook
jstransform.transform('', options);
require.extensions[options.extension || '.js'] = function(module, filename) {
if (!options.hasOwnProperty("react"))
options.react = true;
var src = fs.readFileSync(filename, {encoding: 'utf8'});
if (typeof options.additionalTransform == 'function') {
src = options.additionalTransform(src);
}
try {
src = jstransform.transform(src, options).code;
} catch (e) {
throw new Error('Error transforming ' + filename + ' to JS: ' + e.toString());
}
module._compile(src, filename);
};
installed = true;
}
module.exports = {
install: install
};