Files
react/jest/preprocessor.js
Ben Alpert 93a782b40b Use Babel to build React
Size comparison:

```
   raw     gz Compared to master @ 6ed98ec0c8
     =      = build/JSXTransformer.js
-15736  -3247 build/react-with-addons.js
  +287     +7 build/react-with-addons.min.js
-14412  -2887 build/react.js
  +274    +15 build/react.min.js
```

Differences mostly look to be various bits of whitespace that Babel ends up removing during its transforms (https://gist.github.com/spicyj/21ef31f4d95fb7a58daf). In minified files, mostly additions of `"use strict";`.
2015-05-04 14:14:09 -07:00

32 lines
752 B
JavaScript

'use strict';
var babel = require('babel-core');
var coffee = require('coffee-script');
var tsPreprocessor = require('./ts-preprocessor');
var defaultLibraries = [
require.resolve('./jest.d.ts'),
require.resolve('../src/modern/class/React.d.ts')
];
var ts = tsPreprocessor(defaultLibraries);
module.exports = {
process: function(src, path) {
if (path.match(/\.coffee$/)) {
return coffee.compile(src, {'bare': true});
}
if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
return ts.compile(src, path);
}
if (!path.match(/\/node_modules\//)) {
return babel.transform(src, {
blacklist: ['spec.functionName', 'validation.react'],
filename: path
}).code;
}
return src;
}
};