-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtransformer.js
63 lines (61 loc) · 1.98 KB
/
transformer.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const babel = require("babel-core");
/**
* This is your `.babelrc` equivalent.
*/
const babelRC = {
presets: [require("babel-preset-react-native")],
plugins: [
// The following plugin will rewrite imports. Reimplementations of node
// libraries such as `assert`, `buffer`, etc. will be picked up
// automatically by the React Native packager. All other built-in node
// libraries get rewritten to their browserify counterpart.
[
require("babel-plugin-rewrite-require"),
{
aliases: {
constants: "constants-browserify",
crypto: "crypto-browserify",
dns: "node-libs-browser/mock/dns",
domain: "domain-browser",
fs: "react-native-level-fs",
http: "stream-http",
https: "https-browserify",
net: "node-libs-browser/mock/net",
os: "os-browserify/browser",
path: "path-browserify",
querystring: "querystring-es3",
stream: "stream-browserify",
_stream_duplex: "readable-stream/duplex",
_stream_passthrough: "readable-stream/passthrough",
_stream_readable: "readable-stream/readable",
_stream_transform: "readable-stream/transform",
_stream_writable: "readable-stream/writable",
sys: "util",
timers: "timers-browserify",
tls: "node-libs-browser/mock/tls",
tty: "tty-browserify",
vm: "vm-browserify",
zlib: "browserify-zlib",
pbkdf2: "pbkdf2/browser",
"websocket-stream": "websocket-stream/stream",
cuid: "uuid"
},
throwForNonStringLiteral: true
}
]
],
sourceMaps: true
};
module.exports.transform = function transform(src, filename, options) {
const babelConfig = Object.assign({}, babelRC, {
filename,
sourceFileName: filename
});
const result = babel.transform(src, babelConfig);
return {
ast: result.ast,
code: result.code,
map: result.map,
filename: filename
};
};